Submission #1043368

# Submission time Handle Problem Language Result Execution time Memory
1043368 2024-08-04T08:52:56 Z Pekiban Pipes (CEOI15_pipes) C++17
40 / 100
620 ms 65536 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) {
    if (get(u) == get(v))   return 0;
    p[get(v)] = get(u);
    g[u].pb(v); g[v].pb(u);
    return 1;
}
void upd(int u, int v) {
    int x = rng() % (1LL << 31);
    dp[u] ^= x;
    dp[v] ^= x;
}
void dfs(int s, int e = 0) {
    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))   upd(u, v);
    }
    for (int i = 1; i <= n; ++i) {
        if (!vis[get(i)]) {
            dfs(get(i));
            vis[get(i)] = 1;
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3676 KB Output is correct
2 Correct 1 ms 3676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3932 KB Output is correct
2 Correct 2 ms 3932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 3672 KB Output is correct
2 Correct 49 ms 3672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 85 ms 4084 KB Output is correct
2 Correct 98 ms 3932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 138 ms 4540 KB Output is correct
2 Runtime error 154 ms 17236 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 219 ms 5864 KB Output is correct
2 Runtime error 168 ms 21888 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 300 ms 6520 KB Output is correct
2 Runtime error 322 ms 39540 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 406 ms 6912 KB Output is correct
2 Runtime error 385 ms 48208 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 501 ms 6916 KB Output is correct
2 Runtime error 490 ms 59732 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 609 ms 8784 KB Output is correct
2 Runtime error 620 ms 65536 KB Memory limit exceeded
3 Halted 0 ms 0 KB -