#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define debug(args...) fprintf(stderr,args)
#define FOR(i,a,b) for(int i = a; i <= b; ++i)
#define REP(i,a,b) for(int i = a; i >= b; --i)
typedef long long ll;
typedef pair<int,int>pii;
const int maxn = 1e5 + 10;
int n, m;
map<pii,int>cnt;
struct dsu{
int par[maxn];
int sz[maxn];
void init(){
FOR(i,1,n){
par[i] = i;
sz[i] = 1;
}
}
int root(int v){
if(par[v] == v) return v;
return root(par[v]);
}
void merge(int x, int y){
x = root(x);
y = root(y);
if(x == y) return;
if(sz[y] > sz[x]) swap(x,y);
par[y] = x;
sz[x] += sz[y];
}
} T[2];
void add(int u, int v){
if(u > v) swap(u,v);
pii p = pii(u,v);
++cnt[p];
}
int e(int u, int v){
if(u > v) swap(u,v);
pii p = pii(u,v);
return cnt[p];
}
vector<int>adj[maxn];
int h[maxn], low[maxn], cur;
bool mrk[maxn];
void dfs(int v, int par){
mrk[v] = true;
low[v] = h[v] = ++cur;
for(int i = 0; i < adj[v].size(); ++i){
int u = adj[v][i];
if(u == par) continue;
if(!mrk[u]){
dfs(u,v);
low[v] = min(low[v],low[u]);
if(low[u] > h[v] && e(u,v) == 1) printf("%d %d\n",u,v);
}
else low[v] = min(low[v],h[u]);
}
}
void tarjan(){
FOR(i,1,n)
if(!mrk[i])
dfs(i,-1);
}
int main(){
scanf("%d%d",&n,&m);
T[0].init();
T[1].init();
FOR(i,1,m){
int a, b;
scanf("%d%d",&a,&b);
if(T[0].root(a) != T[0].root(b)){
adj[a].pb(b);
adj[b].pb(a);
T[0].merge(a,b);
add(a,b);
}
else if(T[1].root(a) != T[1].root(b)){
adj[a].pb(b);
adj[b].pb(a);
T[1].merge(a,b);
add(a,b);
}
}
tarjan();
return 0;
}
Compilation message
pipes.cpp: In function 'void dfs(int, int)':
pipes.cpp:63:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < adj[v].size(); ++i){
~~^~~~~~~~~~~~~~~
pipes.cpp: In function 'int main()':
pipes.cpp:82:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&m);
~~~~~^~~~~~~~~~~~~~
pipes.cpp:88:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&a,&b);
~~~~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2688 KB |
Output is correct |
2 |
Correct |
4 ms |
2688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
3840 KB |
Output is correct |
2 |
Correct |
11 ms |
3584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
146 ms |
3632 KB |
Output is correct |
2 |
Correct |
142 ms |
3340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
261 ms |
5108 KB |
Output is correct |
2 |
Correct |
304 ms |
4600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
486 ms |
8796 KB |
Output is correct |
2 |
Correct |
432 ms |
8128 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
841 ms |
20640 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 |
1204 ms |
23408 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 |
1583 ms |
28132 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 |
1892 ms |
28204 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 |
2413 ms |
26920 KB |
Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |
2 |
Halted |
0 ms |
0 KB |
- |