# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
100591 |
2019-03-12T14:53:21 Z |
doowey |
Pipes (CEOI15_pipes) |
C++14 |
|
1238 ms |
13148 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;
}
vector<int> T[N];
int tin[N];
int low[N];
bool vis[N];
int timer;
void dfs(int u, int par){
tin[u] = timer ++ ;
low[u] = tin[u];
vis[u] = true;
for(auto x : T[u]){
if(x==par) continue;
if(vis[x]){
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_back(v);
T[v].push_back(u);
}
else if(merge2(u,v)){
T[u].push_back(v);
T[v].push_back(u);
}
}
for(int i = 1; i <= n; i ++ )if(!vis[i]) dfs(i,-1);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2688 KB |
Output is correct |
2 |
Correct |
4 ms |
2688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
3200 KB |
Output is correct |
2 |
Correct |
7 ms |
2944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
99 ms |
3040 KB |
Output is correct |
2 |
Correct |
99 ms |
2912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
162 ms |
3716 KB |
Output is correct |
2 |
Correct |
189 ms |
3320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
288 ms |
5172 KB |
Output is correct |
2 |
Correct |
260 ms |
4856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
471 ms |
10104 KB |
Output is correct |
2 |
Correct |
364 ms |
7132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
696 ms |
11104 KB |
Output is correct |
2 |
Correct |
618 ms |
8824 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
824 ms |
13148 KB |
Output is correct |
2 |
Correct |
818 ms |
9208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1022 ms |
13148 KB |
Output is correct |
2 |
Correct |
967 ms |
9196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1238 ms |
12644 KB |
Output is correct |
2 |
Correct |
1153 ms |
10340 KB |
Output is correct |