# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1081677 |
2024-08-30T09:07:29 Z |
TB_ |
Pipes (CEOI15_pipes) |
C++17 |
|
743 ms |
65536 KB |
#include <bits/stdc++.h>
using namespace std;
#define ll int
#define fo(i, n) for(ll i = 0; i<(n); i++)
#define F first
#define S second
#define pb push_back
#define deb(x) cout << #x << " = " << (x) << endl
#define deb2(x, y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
typedef vector<int> vl;
typedef vector<vl> vvl;
struct UnionFind{
int n;
vl p;
UnionFind(int n){
p.resize(n);
fo(i, n) p[i] = i;
}
int find(int x){
if(p[x] == x) return x;
return p[x] = find(p[x]);
}
bool same(int a, int b){
return find(a) == find(b);
}
void unite(int a, int b){
a = find(a);
b = find(b);
if(rand()%2) swap(a, b);
p[b] = a;
}
};
int main(){
cin.tie(0)->sync_with_stdio(0);
int n, m, from, to;
cin >> n >> m;
vl xorv(n, 0), amount(n, 0), hash(n, 0);
UnionFind uf(n);
mt19937 rng(42);
fo(i, m){
cin >> from >> to;
from--; to--;
if(uf.same(from, to)){
ll val = rng();
hash[from]^=val;
hash[to]^=val;
}else{
amount[from]++;
amount[to]++;
xorv[from]^=to;
xorv[to]^=from;
uf.unite(from, to);
}
}
fo(i, n){
ll pos = i;
while(1){
if(amount[pos] != 1) break;
ll edge = xorv[pos];
if(!hash[pos]) cout << pos+1 << " " << edge+1 << "\n";
amount[pos]--;
amount[edge]--;
xorv[pos]^=edge;
xorv[edge]^=pos;
hash[edge]^=hash[pos];
pos = edge;
if(amount[edge] != 1) break;
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
348 KB |
Output is correct |
2 |
Correct |
57 ms |
484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
122 ms |
600 KB |
Output is correct |
2 |
Correct |
128 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
164 ms |
600 KB |
Output is correct |
2 |
Correct |
161 ms |
14676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
211 ms |
1368 KB |
Output is correct |
2 |
Runtime error |
202 ms |
19796 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
347 ms |
1628 KB |
Output is correct |
2 |
Runtime error |
394 ms |
34956 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
449 ms |
1884 KB |
Output is correct |
2 |
Runtime error |
452 ms |
43200 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
556 ms |
2004 KB |
Output is correct |
2 |
Runtime error |
563 ms |
54612 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
685 ms |
1884 KB |
Output is correct |
2 |
Runtime error |
743 ms |
65536 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |