답안 #167287

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
167287 2019-12-07T08:00:55 Z mhy908 Pipes (CEOI15_pipes) C++14
50 / 100
1872 ms 23584 KB
#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{
    vector<int> par;
    UNION_FIND(){par.resize(100001);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, t;
vector<int> disc, lowlink, par;
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);
        }
    }
    vector<int>().swap(uf1.par);
    vector<int>().swap(uf2.par);
    disc.resize(100001);
    lowlink.resize(100001);
    par.resize(100001);
    for(int i=1; i<=n; i++){
        if(!disc[i])dfs(i);
    }
}

Compilation message

pipes.cpp: In function 'void dfs(int)':
pipes.cpp:24: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:39: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:42: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 6 ms 3804 KB Output is correct
2 Correct 6 ms 3800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 4312 KB Output is correct
2 Correct 14 ms 4184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 145 ms 8724 KB Output is correct
2 Correct 144 ms 4952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 254 ms 10472 KB Output is correct
2 Correct 301 ms 12124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 434 ms 12124 KB Output is correct
2 Correct 361 ms 9180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 609 ms 19236 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 963 ms 18608 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1254 ms 21004 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1544 ms 22252 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1872 ms 23584 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -