Submission #1055885

# Submission time Handle Problem Language Result Execution time Memory
1055885 2024-08-13T06:17:41 Z rtonbe Keys (IOI21_keys) C++17
37 / 100
3000 ms 1793356 KB
#include <bits/stdc++.h>
using namespace std;
struct node {
    int root;
    set<int> key;
    set<pair<int,int>> adj;
    bool dead = false;
};
const int maxn = 2e5 + 5, INF = 1e9;
int n, m;
node info[maxn];
int fa[maxn];
int vis[maxn];
int rt(int u) {
    if (fa[u]==u) return u;
    else return fa[u] = rt(fa[u]);
}
void merge(int u, int v) {
    int root = info[v].root;
    if (info[u].key.size() + info[v].adj.size() > info[u].key.size() + info[v].adj.size()) swap(u, v);
    for (int x:info[u].key) info[v].key.insert(x);
    for (pair<int,int> x:info[u].adj) info[v].adj.insert(x);
    info[v].root = root;
    fa[u] = v;
}

bool dfs(int u) {
    bool done = true;
    while (done) {
        done = false;
        u = rt(u);
        vis[u] = 1;
        for (int k:info[u].key) {
            pair<int,int> cur;
            int v;
            while (true) {
                cur = *info[u].adj.lower_bound(make_pair(k, 0));
                if (cur.first!=k) break;
                v = rt(cur.second);
                if (u==v) {info[u].adj.erase(cur); continue;}
                else break;
            }
            if (cur.first!=k) continue;
            // cout << u << " " << v << endl;
            if (vis[v]==2) {info[u].dead = true; return false;}
            if (vis[v]==1) {merge(u, v); return true;}
            if (dfs(v)) {
                v = rt(v);
                if (rt(u) == v) {done = true; break;}
                else {merge(u, v); return true;}
            } else {
                info[u].dead = true;
                return false;
            }
        }
    }
    vis[u] = 2;
    return false;
}

vector<int> find_reachable(vector<int> r, vector<int> U, vector<int> V, vector<int> C) {
	n = r.size();
    for (int i=0;i<n;i++){
        info[i].key.insert(r[i]);
        fa[i] = i;
        info[i].root = i;
        info[i].adj.insert({INF, INF});
    }
    int m = U.size();
    for (int i=0;i<m;i++) {
        info[U[i]].adj.insert({C[i], V[i]});
        info[V[i]].adj.insert({C[i], U[i]});
    }
    for (int i=0;i<n;i++) if (!vis[i]) dfs(i);

    // for (int i=0;i<n;i++) cout << rt(i) << " "; cout << endl;

    int sz[n];
    for (int i=0;i<n;i++) sz[i] = 0;
    for (int i=0;i<n;i++) if (!info[rt(i)].dead) {
        sz[rt(i)]++;
    }
    int mn = INF;
    for (int i=0;i<n;i++) if (!info[rt(i)].dead) {
        mn = min(sz[rt(i)], mn);
    }
    vector<int> ans(n, 0);
    for (int i=0;i<n;i++) ans[i] = (!info[rt(i)].dead && sz[rt(i)]==mn);
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 22364 KB Output is correct
2 Correct 9 ms 22320 KB Output is correct
3 Correct 8 ms 22256 KB Output is correct
4 Correct 8 ms 22328 KB Output is correct
5 Correct 9 ms 22364 KB Output is correct
6 Correct 8 ms 22364 KB Output is correct
7 Correct 8 ms 22360 KB Output is correct
8 Correct 9 ms 22364 KB Output is correct
9 Correct 9 ms 22364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 22364 KB Output is correct
2 Correct 9 ms 22320 KB Output is correct
3 Correct 8 ms 22256 KB Output is correct
4 Correct 8 ms 22328 KB Output is correct
5 Correct 9 ms 22364 KB Output is correct
6 Correct 8 ms 22364 KB Output is correct
7 Correct 8 ms 22360 KB Output is correct
8 Correct 9 ms 22364 KB Output is correct
9 Correct 9 ms 22364 KB Output is correct
10 Correct 8 ms 22364 KB Output is correct
11 Correct 8 ms 22188 KB Output is correct
12 Correct 8 ms 22364 KB Output is correct
13 Correct 9 ms 22280 KB Output is correct
14 Correct 9 ms 22364 KB Output is correct
15 Correct 8 ms 22360 KB Output is correct
16 Correct 8 ms 22212 KB Output is correct
17 Correct 8 ms 22364 KB Output is correct
18 Correct 8 ms 22360 KB Output is correct
19 Correct 8 ms 22364 KB Output is correct
20 Correct 8 ms 22360 KB Output is correct
21 Correct 11 ms 22324 KB Output is correct
22 Correct 9 ms 22364 KB Output is correct
23 Correct 8 ms 22364 KB Output is correct
24 Correct 9 ms 22616 KB Output is correct
25 Correct 8 ms 22364 KB Output is correct
26 Correct 9 ms 22364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 22364 KB Output is correct
2 Correct 9 ms 22320 KB Output is correct
3 Correct 8 ms 22256 KB Output is correct
4 Correct 8 ms 22328 KB Output is correct
5 Correct 9 ms 22364 KB Output is correct
6 Correct 8 ms 22364 KB Output is correct
7 Correct 8 ms 22360 KB Output is correct
8 Correct 9 ms 22364 KB Output is correct
9 Correct 9 ms 22364 KB Output is correct
10 Correct 8 ms 22364 KB Output is correct
11 Correct 8 ms 22188 KB Output is correct
12 Correct 8 ms 22364 KB Output is correct
13 Correct 9 ms 22280 KB Output is correct
14 Correct 9 ms 22364 KB Output is correct
15 Correct 8 ms 22360 KB Output is correct
16 Correct 8 ms 22212 KB Output is correct
17 Correct 8 ms 22364 KB Output is correct
18 Correct 8 ms 22360 KB Output is correct
19 Correct 8 ms 22364 KB Output is correct
20 Correct 8 ms 22360 KB Output is correct
21 Correct 11 ms 22324 KB Output is correct
22 Correct 9 ms 22364 KB Output is correct
23 Correct 8 ms 22364 KB Output is correct
24 Correct 9 ms 22616 KB Output is correct
25 Correct 8 ms 22364 KB Output is correct
26 Correct 9 ms 22364 KB Output is correct
27 Correct 9 ms 22684 KB Output is correct
28 Correct 9 ms 22620 KB Output is correct
29 Correct 9 ms 22620 KB Output is correct
30 Correct 9 ms 22632 KB Output is correct
31 Correct 8 ms 22364 KB Output is correct
32 Correct 9 ms 22352 KB Output is correct
33 Correct 9 ms 22372 KB Output is correct
34 Correct 12 ms 22628 KB Output is correct
35 Correct 9 ms 22624 KB Output is correct
36 Correct 9 ms 22876 KB Output is correct
37 Correct 14 ms 23192 KB Output is correct
38 Correct 10 ms 23140 KB Output is correct
39 Correct 11 ms 23248 KB Output is correct
40 Correct 10 ms 22568 KB Output is correct
41 Correct 9 ms 22920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 22364 KB Output is correct
2 Correct 9 ms 22320 KB Output is correct
3 Correct 8 ms 22256 KB Output is correct
4 Correct 8 ms 22328 KB Output is correct
5 Correct 9 ms 22364 KB Output is correct
6 Correct 8 ms 22364 KB Output is correct
7 Correct 8 ms 22360 KB Output is correct
8 Correct 9 ms 22364 KB Output is correct
9 Correct 9 ms 22364 KB Output is correct
10 Execution timed out 3126 ms 1793356 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 22364 KB Output is correct
2 Correct 9 ms 22320 KB Output is correct
3 Correct 8 ms 22256 KB Output is correct
4 Correct 8 ms 22328 KB Output is correct
5 Correct 9 ms 22364 KB Output is correct
6 Correct 8 ms 22364 KB Output is correct
7 Correct 8 ms 22360 KB Output is correct
8 Correct 9 ms 22364 KB Output is correct
9 Correct 9 ms 22364 KB Output is correct
10 Correct 8 ms 22364 KB Output is correct
11 Correct 8 ms 22188 KB Output is correct
12 Correct 8 ms 22364 KB Output is correct
13 Correct 9 ms 22280 KB Output is correct
14 Correct 9 ms 22364 KB Output is correct
15 Correct 8 ms 22360 KB Output is correct
16 Correct 8 ms 22212 KB Output is correct
17 Correct 8 ms 22364 KB Output is correct
18 Correct 8 ms 22360 KB Output is correct
19 Correct 8 ms 22364 KB Output is correct
20 Correct 8 ms 22360 KB Output is correct
21 Correct 11 ms 22324 KB Output is correct
22 Correct 9 ms 22364 KB Output is correct
23 Correct 8 ms 22364 KB Output is correct
24 Correct 9 ms 22616 KB Output is correct
25 Correct 8 ms 22364 KB Output is correct
26 Correct 9 ms 22364 KB Output is correct
27 Correct 9 ms 22684 KB Output is correct
28 Correct 9 ms 22620 KB Output is correct
29 Correct 9 ms 22620 KB Output is correct
30 Correct 9 ms 22632 KB Output is correct
31 Correct 8 ms 22364 KB Output is correct
32 Correct 9 ms 22352 KB Output is correct
33 Correct 9 ms 22372 KB Output is correct
34 Correct 12 ms 22628 KB Output is correct
35 Correct 9 ms 22624 KB Output is correct
36 Correct 9 ms 22876 KB Output is correct
37 Correct 14 ms 23192 KB Output is correct
38 Correct 10 ms 23140 KB Output is correct
39 Correct 11 ms 23248 KB Output is correct
40 Correct 10 ms 22568 KB Output is correct
41 Correct 9 ms 22920 KB Output is correct
42 Execution timed out 3126 ms 1793356 KB Time limit exceeded
43 Halted 0 ms 0 KB -