# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
100506 |
2019-03-11T19:55:42 Z |
doowey |
Pipes (CEOI15_pipes) |
C++14 |
|
1522 ms |
5112 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){
while(x!=pi[x]){
x=pi[x];
}
return 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];
int tin[N];
int low[N];
int timer;
bool vis[N];
void dfs(int node, int par){
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] && B.fin(x) != B.fin(node)){
cout << x << " " << node << "\n";
}
}
}
}
int main(){
fastIO;
A.Init();
B.Init();
int n, m;
cin >> n >> m;
int u, v;
int cnt = 0;
for(int i = 0 ; i < m ; i ++ ){
cin >> u >> v;
if(A.unite(u,v)){
// T[u].push_back(v);
// T[v].push_back(u);
cnt += 2 ;
}
else if(B.unite(u,v)){
// T[u].push_back(v);
// T[v].push_back(u);
cnt += 2;
}
}
assert(cnt <= (int)4e5);
for(int i = 1; i <= n; i ++ )
if(!vis[i])dfs(i,-1);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
4224 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
4324 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
120 ms |
4304 KB |
Output is correct |
2 |
Incorrect |
113 ms |
4224 KB |
Wrong number of edges |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
195 ms |
4296 KB |
Output is correct |
2 |
Incorrect |
228 ms |
4296 KB |
Wrong number of edges |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
325 ms |
4444 KB |
Output is correct |
2 |
Incorrect |
275 ms |
4552 KB |
Wrong number of edges |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
438 ms |
4808 KB |
Output is correct |
2 |
Incorrect |
384 ms |
4828 KB |
Wrong number of edges |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
710 ms |
4936 KB |
Output is correct |
2 |
Incorrect |
694 ms |
4940 KB |
Wrong number of edges |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
925 ms |
5064 KB |
Output is correct |
2 |
Incorrect |
932 ms |
5112 KB |
Wrong number of edges |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1191 ms |
5068 KB |
Output is correct |
2 |
Incorrect |
1149 ms |
5072 KB |
Wrong number of edges |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1479 ms |
5068 KB |
Output is correct |
2 |
Incorrect |
1522 ms |
5080 KB |
Wrong number of edges |