제출 #97552

#제출 시각아이디문제언어결과실행 시간메모리
97552jasony123123Pipes (CEOI15_pipes)C++11
100 / 100
1514 ms12476 KiB
    #include <cstdio>
    #include <vector>
    using namespace std;
    #define pb push_back
    typedef pair<int,int> pp;
     
    int n, m;
     
    struct unf {
    	int par[100010];
    	void init(){ for(int i=1; i<=n; ++i) par[i]=i; }
     
    	int root(int x){ return (x==par[x])?x:(par[x]=root(par[x])); }
    	bool merge(int a,int b){
    		a=root(a); b=root(b);
    		if(a==b) return false;
    		par[a]=b;
    		return true;
    	}
    } f1, f2;
     
    int par[100010];
    int idx[100010];
    int lowl[100010];
    int nt;
    vector<int> edge[100010];
     
    void dfs(int x){
    	idx[x] = lowl[x] = ++nt;
    	bool cl = false;
    	for(int y:edge[x]){
    		if(par[x] == y && !cl){
    			cl=true; continue;
    		}
    		if(!idx[y]){
    			par[y]=x;
    			dfs(y);
    			lowl[x] = min(lowl[x], lowl[y]);
    		} else lowl[x] = min(lowl[x], idx[y]);
    	}
    	if(par[x] && idx[x]==lowl[x]) printf("%d %d\n", x, par[x]);
    }
     
    int main(){
    	scanf("%d%d", &n, &m);
    	f1.init(); f2.init();
    for(;m--;){
    	int a,b;
    	scanf("%d%d", &a, &b);
    	if(f1.merge(a,b) || f2.merge(a,b)) edge[a].pb(b), edge[b].pb(a);
    }
    	for(int i=1; i<=n; ++i) if(par[i]==0) dfs(i);
    	return 0;
    }

컴파일 시 표준 에러 (stderr) 메시지

pipes.cpp: In function 'int main()':
pipes.cpp:45:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
      scanf("%d%d", &n, &m);
      ~~~~~^~~~~~~~~~~~~~~~
pipes.cpp:49:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
      scanf("%d%d", &a, &b);
      ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...