# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
100622 |
2019-03-12T21:23:16 Z |
doowey |
Pipes (CEOI15_pipes) |
C++14 |
|
1284 ms |
13040 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N = (int)1e5+1;
int n1[N];
int n2[N];
int fin1(int x){
if(n1[x]==x)
return x;
return n1[x]=fin1(n1[x]);
}
int fin2(int x){
if(n2[x]==x)
return x;
return n2[x]=fin2(n2[x]);
}
bool merge1(int a, int b){
a=fin1(a);
b=fin1(b);
if(a==b) return false;
n1[a]=b;
return true;
}
bool merge2(int a,int b){
a=fin2(a);
b=fin2(b);
if(a==b) return false;
n2[a]=b;
return true;
}
priority_queue <int> T[N];
int tin[N];
int low[N];
int timer;
void dfs(int u, int par){
tin[u] = ++ timer ;
low[u] = tin[u];
int x;
while(!T[u].empty()){
x = T[u].top();
T[u].pop();
if(x==par) continue;
if(tin[x] != 0){
low[u] = min(low[u], tin[x]);
}
else{
dfs(x,u);
low[u] = min(low[u], low[x]);
if(tin[u]<low[x] && fin2(u) != fin2(x)){
cout << u << " " << x << "\n";
}
}
}
}
int main(){
fastIO;
int n, m;
cin >> n >> m;
for(int i = 1; i <= n; i ++ ){
n1[i]=i;
n2[i]=i;
}
int u, v;
for(int i = 0 ; i < m ; i ++ ){
cin >> u >> v;
if(merge1(u,v)){
T[u].push(v);
T[v].push(u);
}
else if(merge2(u,v)){
T[u].push(v);
T[v].push(u);
}
}
for(int i = 1; i <= n; i ++ )if(tin[i] == 0) dfs(i,-1);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
3456 KB |
Output is correct |
2 |
Correct |
4 ms |
3456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
3868 KB |
Output is correct |
2 |
Correct |
9 ms |
3712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
99 ms |
3824 KB |
Output is correct |
2 |
Correct |
96 ms |
3704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
162 ms |
4344 KB |
Output is correct |
2 |
Correct |
190 ms |
4088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
288 ms |
5692 KB |
Output is correct |
2 |
Correct |
251 ms |
5492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
440 ms |
10340 KB |
Output is correct |
2 |
Correct |
385 ms |
7784 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
646 ms |
11260 KB |
Output is correct |
2 |
Correct |
603 ms |
9020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
897 ms |
13032 KB |
Output is correct |
2 |
Correct |
847 ms |
9608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1112 ms |
13040 KB |
Output is correct |
2 |
Correct |
1010 ms |
9596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1284 ms |
12516 KB |
Output is correct |
2 |
Correct |
1164 ms |
10448 KB |
Output is correct |