# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
669594 |
2022-12-06T19:55:44 Z |
Iliya_ |
Pipes (CEOI15_pipes) |
C++17 |
|
1066 ms |
63560 KB |
// IN THE NAME OF GOD
#include<bits/stdc++.h>
#pragma GCC optimize ("O2,unroll-loops")
#define endl '\n';
#define file_reading freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
using namespace std;
typedef long long ll;
typedef long double dll;
typedef unsigned long long ull;
// Variables
const int B = 1e5+7;
const int BB = 6e6+7;;
pair<int,int> v[BB];
int par1[B];
int par2[B];
int n,m,a,b,one,two;
vector<pair<int,int>> g[B];
bool seen[B];
int father[B];
int dist[B];
int val[B];
// main functions
int get_root1(int v){
return (par1[v] == v ? v : par1[v] = get_root1(par1[v]));
}
int get_root2(int v){
return (par2[v] == v ? v : par2[v] = get_root2(par2[v]));
}
bool merge1(int v, int u){
one = get_root1(v);
two = get_root1(u);
if (one == two){return 0;}
par1[one] = two;
return 1;
}
bool merge2(int v, int u){
one = get_root2(v);
two = get_root2(u);
if (one == two){return 0;}
par2[one] = two;
return 1;
}
void dfs(int vv){
seen[vv] = 1;
for(auto cur : g[vv]){
int u = cur.first;
if (seen[u] == 0){
father[u] = vv;
dist[u] = dist[vv] + 1;
dfs(u);
val[vv] += val[u];
if (val[u] == 0){cout << v[cur.second].first << " " << v[cur.second].second << endl;}
}
else if (father[u] != vv && father[vv] != u && dist[u] < dist[vv]){
val[u]--;
val[vv]++;
}
}
}
int32_t main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n >> m;
for(int i=1; i<=n; i++){par1[i] = par2[i] = i;}
for(int i=1; i<=m; i++){
cin >> v[i].first >> v[i].second;
if (merge1(v[i].first,v[i].second)){
g[v[i].first].push_back({v[i].second,i});
g[v[i].second].push_back({v[i].first,i});
}
else if (merge2(v[i].first,v[i].second)){
g[v[i].first].push_back({v[i].second,i});
g[v[i].second].push_back({v[i].first,i});
}
}
for(int i=1; i<=n; i++){
if (seen[i] == 0){
father[i] = 0;
dist[i] = 0;
dfs(i);
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Incorrect |
2 ms |
2644 KB |
Wrong number of edges |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
3412 KB |
Output is correct |
2 |
Incorrect |
5 ms |
3156 KB |
Wrong number of edges |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
100 ms |
7888 KB |
Output is correct |
2 |
Incorrect |
85 ms |
7500 KB |
Wrong number of edges |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
146 ms |
12004 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
256 ms |
17876 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
340 ms |
27140 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
524 ms |
37356 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
696 ms |
47188 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
941 ms |
55108 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1066 ms |
63560 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |