Submission #1050452

# Submission time Handle Problem Language Result Execution time Memory
1050452 2024-08-09T09:43:05 Z Zicrus Keys (IOI21_keys) C++17
37 / 100
3000 ms 28540 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

ll n;
vector<vector<pair<ll, ll>>> edges;
vector<int> r;

vector<ll> lnk;
vector<ll> sz;

ll find(ll a) {
    if (a != lnk[a]) lnk[a] = find(lnk[a]);
    return lnk[a];
}

bool unite(ll a, ll b) {
    a = find(a); b = find(b);
    if (a == b) return false;
    if (sz[a] > sz[b]) swap(a, b);
    lnk[a] = b;
    sz[b] += sz[a];
    return true;
}

ll solve(ll start) {
    lnk = vector<ll>(n);
    sz = vector<ll>(n, 1);
    for (int i = 0; i < n; i++) lnk[i] = i;
    vector<vector<ll>> adj(n);
    vector<bool> vst(n);
    vector<bool> hasKey(n);

    queue<ll> q;
    q.push(start);
    while (!q.empty()) {
        ll cur = q.front(); q.pop();
        if (vst[cur]) continue;
        vst[cur] = true;
        if (!hasKey[r[cur]]) {
            for (auto &e : edges[r[cur]]) {
                if (!unite(e.first, e.second)) continue;
                if (vst[e.first] || vst[e.second]) {
                    q.push(e.first);
                    q.push(e.second);
                }
                adj[e.first].push_back(e.second);
                adj[e.second].push_back(e.first);
            }
        }
        for (auto &e : adj[cur]) {
            q.push(e);
        }
    }

    return sz[find(start)];
}

vector<int> find_reachable(vector<int> r1, vector<int> u, vector<int> v, vector<int> c) {
    r = r1;
    n = r.size();
	edges = vector<vector<pair<ll, ll>>>(n);
    for (int i = 0; i < c.size(); i++) {
        edges[c[i]].push_back({u[i], v[i]});
    }

    vector<int> res(n);
    int mn = 1ll << 30ll;
    for (int i = 0; i < n; i++) {
        res[i] = solve(i);
        mn = min(mn, res[i]);
    }
    for (auto &e : res) {
        e = e == mn;
    }

    return res;
}

Compilation message

keys.cpp: In function 'std::vector<int> find_reachable(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
keys.cpp:64:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |     for (int i = 0; i < c.size(); i++) {
      |                     ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 9 ms 472 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 13 ms 460 KB Output is correct
9 Correct 28 ms 444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 9 ms 472 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 13 ms 460 KB Output is correct
9 Correct 28 ms 444 KB Output is correct
10 Correct 2 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 428 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 436 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 3 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 3 ms 348 KB Output is correct
24 Correct 3 ms 348 KB Output is correct
25 Correct 5 ms 464 KB Output is correct
26 Correct 3 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 9 ms 472 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 13 ms 460 KB Output is correct
9 Correct 28 ms 444 KB Output is correct
10 Correct 2 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 428 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 436 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 3 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 3 ms 348 KB Output is correct
24 Correct 3 ms 348 KB Output is correct
25 Correct 5 ms 464 KB Output is correct
26 Correct 3 ms 348 KB Output is correct
27 Correct 135 ms 600 KB Output is correct
28 Correct 113 ms 848 KB Output is correct
29 Correct 83 ms 604 KB Output is correct
30 Correct 55 ms 572 KB Output is correct
31 Correct 5 ms 600 KB Output is correct
32 Correct 3 ms 348 KB Output is correct
33 Correct 5 ms 348 KB Output is correct
34 Correct 62 ms 604 KB Output is correct
35 Correct 53 ms 348 KB Output is correct
36 Correct 206 ms 752 KB Output is correct
37 Correct 153 ms 600 KB Output is correct
38 Correct 317 ms 804 KB Output is correct
39 Correct 311 ms 696 KB Output is correct
40 Correct 55 ms 604 KB Output is correct
41 Correct 321 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 9 ms 472 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 13 ms 460 KB Output is correct
9 Correct 28 ms 444 KB Output is correct
10 Execution timed out 3091 ms 28540 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 9 ms 472 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 13 ms 460 KB Output is correct
9 Correct 28 ms 444 KB Output is correct
10 Correct 2 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 428 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 436 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 3 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 3 ms 348 KB Output is correct
24 Correct 3 ms 348 KB Output is correct
25 Correct 5 ms 464 KB Output is correct
26 Correct 3 ms 348 KB Output is correct
27 Correct 135 ms 600 KB Output is correct
28 Correct 113 ms 848 KB Output is correct
29 Correct 83 ms 604 KB Output is correct
30 Correct 55 ms 572 KB Output is correct
31 Correct 5 ms 600 KB Output is correct
32 Correct 3 ms 348 KB Output is correct
33 Correct 5 ms 348 KB Output is correct
34 Correct 62 ms 604 KB Output is correct
35 Correct 53 ms 348 KB Output is correct
36 Correct 206 ms 752 KB Output is correct
37 Correct 153 ms 600 KB Output is correct
38 Correct 317 ms 804 KB Output is correct
39 Correct 311 ms 696 KB Output is correct
40 Correct 55 ms 604 KB Output is correct
41 Correct 321 ms 600 KB Output is correct
42 Execution timed out 3091 ms 28540 KB Time limit exceeded
43 Halted 0 ms 0 KB -