# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1043409 |
2024-08-04T09:09:47 Z |
Pekiban |
Pipes (CEOI15_pipes) |
C++17 |
|
653 ms |
6888 KB |
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
const int N = 1e5+5;
mt19937 rng(time(0));
// upravo sam imao najgenijalniju ideju svih vremena
vector<int> g[N];
int p[N], dp[N], vis[N];
int get(int &x) {
if (x == p[x]) return x;
return p[x] = get(p[x]);
}
bool unite(int u, int v) {
u = get(u), v = get(v);
if (u == v) return 0;
p[v] = u;
return 1;
}
void upd(int &u, int &v) {
int x = rng() % (1LL << 30);
dp[u] ^= x;
dp[v] ^= x;
}
void dfs(int &s, int &e) {
for (auto &u : g[s]) {
if (u == e) continue;
dfs(u, s);
dp[s] ^= dp[u];
}
if (e && !dp[s]) cout << e << ' ' << s << '\n';
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
iota(p, p+N, 0);
int n, m;
cin >> n >> m;
int u, v;
for (int i = 0; i < m; ++i) {
cin >> u >> v;
if (unite(u, v)) {
g[u].pb(v), g[v].pb(u);
}
else {
upd(u, v);
}
}
// for (int i = 1; i <= n; ++i) {
// cout << i << ':';
// for (auto x : g[i]) {
// cout << x << ' ';
// }
// cout << '\n';
// }
// for (int i = 1; i <= n; ++i) cout << dp[i] << ' ';
for (int i = 1; i <= n; ++i) {
if (!vis[get(i)]) {
// cout << get(i) << ' ';
// cout << '\n';
int p = get(i), z = 0;
dfs(p, z);
vis[get(i)] = 1;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3676 KB |
Output is correct |
2 |
Correct |
1 ms |
3676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3932 KB |
Output is correct |
2 |
Correct |
2 ms |
3932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
3672 KB |
Output is correct |
2 |
Correct |
62 ms |
3676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
85 ms |
3928 KB |
Output is correct |
2 |
Correct |
96 ms |
3932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
139 ms |
4440 KB |
Output is correct |
2 |
Correct |
135 ms |
4568 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
217 ms |
5984 KB |
Output is correct |
2 |
Correct |
162 ms |
5980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
283 ms |
6324 KB |
Output is correct |
2 |
Correct |
304 ms |
6092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
438 ms |
6888 KB |
Output is correct |
2 |
Correct |
362 ms |
6844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
484 ms |
6764 KB |
Output is correct |
2 |
Correct |
497 ms |
6736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
633 ms |
6732 KB |
Output is correct |
2 |
Correct |
653 ms |
6888 KB |
Output is correct |