zoukankan      html  css  js  c++  java
  • Network

    https://vjudge.net/contest/411012#problem/B

    这sb题真的就nm离谱

    割点板子题,就是建图比较sb,具体看代码吧

    #include <iostream>
    #include <vector>
    #include <cstring>
    #include <cstdio>
    #include <algorithm>
    #include <string>
    #include <set>
    using namespace std;
    typedef long long ll;
    const int maxn = 2e5+121;
    vector<int> G[maxn];
    void add(int x,int y) {
    	G[x].push_back(y);
    }
    int n;
    int dfn[maxn], low[maxn];
    int cnt[maxn];
    int df;
    
    string sn;
    int tarjan(int x){
    	dfn[x] = low[x] = ++df;
    	int f = 0;
    	
    	for(int i=0;i<G[x].size();i++){
    		int p = G[x][i];
    		if(!dfn[p]){
    			tarjan(p);
    			low[x] = min(low[x],low[p]);
    			
    			if(dfn[x] <= low[p]){
    				f++;
    				if(x != 1 || f > 1){
    					cnt[x] = 1;
    				}
    			}		
    		}	
    		else{
    			low[x] = min(low[x],dfn[p]);
    		}
    	}
    	
    	
    	return 0;
    }
    int main() {
    	while(cin>>n && n) {
    		for(int i=0; i<=n+11; i++) {
    			G[i].clear();
    			dfn[i] = low[i] = 0;
    			cnt[i] = 0;
    		}
    		df = 0;
    		
    		getchar();
    		while(1){
    			int f = 0;
    			int ans = 0;
    			int be;
    			getline(cin,sn);
    			if(sn == "0") break;
    			
    			for (int i = 0; i < sn.size(); i++) {
    				if(sn[i] >= '0' && sn[i] <= '9') {
    					ans *= 10;
    					ans += sn[i] - '0';
    				} 
    				else {
    					if(f == 0) {
    						be = ans;
    						f = 1;
    					} 
    					else {
    						add(be, ans);
    						add(ans, be);
    					}
    					ans = 0;
    				}
    			}
    			add(be,ans);
    			add(ans,be);
    		}
    		
    		tarjan(1);
    		int ans = 0;
    		for(int i=1;i<=n;i++){
    			if(cnt[i])  ans++;
    		}
    		cout<<ans<<endl;
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    基础排序算法之快速排序(Quick Sort)
    基础排序算法之并归排序(Merge Sort)
    Python中With的用法
    Python中AND-OR的用法
    注解/Annotation
    初识Angular2
    Angular 2 入门二
    Angular2 入门
    asp中将系统货币符号¥改为美国货币符号$的做法
    设计模式总结
  • 原文地址:https://www.cnblogs.com/lesning/p/14074560.html
Copyright © 2011-2022 走看看