답안 #167289

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
167289 2019-12-07T08:03:12 Z mhy908 Pipes (CEOI15_pipes) C++14
100 / 100
1957 ms 15444 KB
#pragma GCC optimize "03"
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
struct UNION_FIND{
    int par[100001];
    UNION_FIND(){for(int i=1; i<=100000; i++)par[i]=i;}
    int findpar(int num){return num==par[num]?num:par[num]=findpar(par[num]);}
    void mergepar(int a, int b){par[findpar(a)]=findpar(b);}
    bool query(int a, int b){return findpar(a)==findpar(b);}
}uf1, uf2;
vector<int> link[100001];
int n, m;
int disc[100001], lowlink[100001], par[100001], t;
void dfs(int u)
{
	disc[u]=lowlink[u]=++t;
	bool temp=false;
	for(int i=0; i<link[u].size(); i++){
		if(link[u][i]==par[u]&&!temp)temp=true;
		else{
			if(!disc[link[u][i]]){
				par[link[u][i]]=u;
				dfs(link[u][i]);
				if(lowlink[link[u][i]]>disc[u])printf("%d %d\n", u, link[u][i]);
				lowlink[u]=min(lowlink[u], lowlink[link[u][i]]);
			}
			else lowlink[u]=min(lowlink[u], disc[link[u][i]]);
		}
	}
}
int main()
{
    scanf("%d %d", &n, &m);
    for(int i=1; i<=m; i++){
        int u, v;
        scanf("%d %d", &u, &v);
        if(!uf1.query(u, v)){
            uf1.mergepar(u, v);
            link[u].pb(v);
            link[v].pb(u);
        }
        else if(!uf2.query(u, v)){
            uf2.mergepar(u, v);
            link[u].pb(v);
            link[v].pb(u);
        }
    }
    for(int i=1; i<=n; i++){
        if(!disc[i])dfs(i);
    }
}

Compilation message

pipes.cpp: In function 'void dfs(int)':
pipes.cpp:25:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<link[u].size(); i++){
               ~^~~~~~~~~~~~~~~
pipes.cpp: In function 'int main()':
pipes.cpp:40:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~~
pipes.cpp:43:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &u, &v);
         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3448 KB Output is correct
2 Correct 5 ms 3448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 3960 KB Output is correct
2 Correct 11 ms 3832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 143 ms 6136 KB Output is correct
2 Correct 161 ms 4280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 247 ms 5504 KB Output is correct
2 Correct 293 ms 5340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 418 ms 8188 KB Output is correct
2 Correct 349 ms 7800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 619 ms 11376 KB Output is correct
2 Correct 718 ms 8296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 918 ms 13240 KB Output is correct
2 Correct 856 ms 9568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1218 ms 15352 KB Output is correct
2 Correct 1189 ms 10132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1513 ms 15444 KB Output is correct
2 Correct 1442 ms 10152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1957 ms 14788 KB Output is correct
2 Correct 1704 ms 10796 KB Output is correct