# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
100500 |
2019-03-11T19:43:14 Z |
doowey |
Pipes (CEOI15_pipes) |
C++14 |
|
1174 ms |
13940 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 + 9;
struct DSU{
int pi[N];
int sz[N];
int fin(int x){
if(pi[x] == x)
return x;
return pi[x] = fin(pi[x]);
}
bool unite(int a, int b){
a = fin(a);
b = fin(b);
if(a==b)
return false;
if(sz[a] > sz[b])
swap(a, b);
sz[b] += sz[a];
pi[a] = b;
return true;
}
void Init(){
for(int i = 0 ;i < N ; i ++ ){
pi[i] = i;
sz[i] = 1;
}
}
};
DSU A, B;
vector<int> T[N];
vector<pii> answ;
int tin[N];
int low[N];
int timer;
bool vis[N];
void bridge(int a, int b){
if(B.fin(a) != B.fin(b)){
cout << a << " " << b << "\n";
}
}
void dfs(int node, int par){
if(vis[node]){
return;
}
vis[node] = true;
tin[node] = timer ++ ;
low[node] = tin[node];
for(auto x : T[node]){
if(x == par){
continue;
}
if(vis[x]){
low[node] = min(low[node], tin[x]);
}
else{
dfs(x, node);
low[node] = min(low[node], low[x]);
if(tin[node] < low[x]){
bridge(node, x);
}
}
}
}
int main(){
fastIO;
A.Init();
B.Init();
int n, m;
cin >> n >> m;
int u, v;
for(int i = 0 ; i < m ; i ++ ){
cin >> u >> v;
if(A.fin(u) ==A.fin(v)){
if(B.fin(u) == B.fin(v)){
continue;
}
B.unite(u,v);
}
else{
A.unite(u,v);
}
T[u].push_back(v);
T[v].push_back(u);
}
for(int i = 1; i <= n; i ++ )
dfs(i,-1);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
4224 KB |
Output is correct |
2 |
Correct |
5 ms |
4224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
4736 KB |
Output is correct |
2 |
Correct |
8 ms |
4480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
95 ms |
4600 KB |
Output is correct |
2 |
Correct |
94 ms |
4472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
158 ms |
5240 KB |
Output is correct |
2 |
Correct |
184 ms |
4728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
295 ms |
6568 KB |
Output is correct |
2 |
Correct |
261 ms |
6264 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
390 ms |
11108 KB |
Output is correct |
2 |
Correct |
340 ms |
8184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
610 ms |
12028 KB |
Output is correct |
2 |
Correct |
598 ms |
9592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
822 ms |
13940 KB |
Output is correct |
2 |
Correct |
788 ms |
9824 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
983 ms |
13928 KB |
Output is correct |
2 |
Correct |
909 ms |
9792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1174 ms |
13400 KB |
Output is correct |
2 |
Correct |
1139 ms |
11096 KB |
Output is correct |