#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]) continue;
ll edge = xorv[pos];
// deb2(pos+1, edge+1);
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5035 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5046 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5027 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5042 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5071 ms |
604 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
217 ms |
2640 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
335 ms |
3156 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
457 ms |
3536 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
562 ms |
3536 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
707 ms |
8272 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |