High-connectivity components of the uva-1 11504 Dominos

Source: Internet
Author: User

High-connectivity components of the uva-1 11504 Dominos

 

 

Q: If a domino card has an edge u-> v, it means that u has fallen v automatically. The minimum number of manual push requests is required.

If some cards belong to the same strongly connected component, if any card is pushed down, all cards are pushed down. After the point can be scaled down through strong connectivity, there must be no card of entry level.

 

Note that this question cannot be used to determine the number of points with the input degree 0, because there may be a number of strongly connected components, but the input degree is not 0. For example

N = 6, m = 6

1-> 2,

2-> 3,

3-> 1,

4-> 5,

5-> 6,

6-> 4.

Although there is no entry point of 0, it needs to be pushed twice.

 

 

#pragma comment(linker, /STACK:10240000,10240000)#include #include 
 
  #include 
  
   #include 
   
    #include 
    
     #include 
     
      #include 
      
       #include 
       
        #include 
        
         #include 
         
          #include 
          
           #include
           #define mod 4294967296#define MAX 0x3f3f3f3f#define lson o<<1, l, m#define rson o<<1|1, m+1, r#define SZ(x) ((int)ans.size())#define MAKE make_pair#define INFL 0x3f3f3f3f3f3f3f3fLL#define mem(a) memset(a, 0, sizeof(a))const double pi = acos(-1.0);const double eps = 1e-9;const int N = 100005;const int M = 20005;typedef long long ll;using namespace std;int n, m;vector 
            
              G[N];int pre[N], low[N], scc[N], dfs_clock, scc_cnt;stack 
             
               S;int T;void dfs(int u) { pre[u] = low[u] = ++dfs_clock; S.push(u); for(int i = 0; i < G[u].size(); i++) { int v = G[u][i]; if(pre[v] == 0) { dfs(v); low[u] = min(low[u], low[v]); } else if(scc[v] == 0) { low[u] = min(low[u], low[v]); } } if(low[u] == pre[u]) { scc_cnt++; for(;;) { int x = S.top(); S.pop(); scc[x] = scc_cnt; if(x == u) break; } }}void find_scc() { dfs_clock = scc_cnt = 0; mem(scc); mem(pre); for(int i = 0; i < n; i++) { if(pre[i] == 0) dfs(i); }}int vis[N];int main() { //freopen(in.txt,r,stdin); cin >> T; while(T--) { cin >> n >> m; for(int i = 0; i < n; i++) G[i].clear(); for(int i = 0; i < m; i++) { int x, y; scanf(%d%d, &x, &y); x--, y--; G[x].push_back(y); } find_scc(); mem(vis); for(int u = 0; u < n; u++) { for(int i = 0; i < G[u].size(); i++) { int v = G[u][i]; if(scc[v] != scc[u]) { vis[ scc[v] ]++; } } } int cnt = 0; //cout << scc_cnt << endl; for(int i = 1; i <= scc_cnt; i++) { if(vis[i] == 0) cnt++; } cout << cnt << endl; } return 0;}
             
            
          
         
        
       
      
     
    
   
  
 

 

 

??

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.