Submission #441794

# Submission time Handle Problem Language Result Execution time Memory
441794 2021-07-06T07:52:34 Z baluteshih Keys (IOI21_keys) C++17
37 / 100
3000 ms 33188 KB
#include <vector>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define X first
#define Y second
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define SZ(a) ((int)a.size())

vector<int> G[300005];
vector<pii> road[300005];
int conn[300005], vis[300005];
vector<int> stk;

void dfs(int u, vector<int> &r) {
    if (!vis[r[u]])
        stk.pb(r[u]), vis[r[u]] = 1;
    conn[u] = 1;
    for (int i : G[u])
        if (!conn[i])
            dfs(i, r);
}

vector<int> find_reachable(vector<int> r, vector<int> u, vector<int> v, vector<int> c) {
    int n = SZ(r), m = SZ(u);
    vector<int> ans(n, 0);
    vector<int> arr(n, 0);
    for (int i = 0; i < m; ++i)
        road[c[i]].pb(pii(u[i], v[i]));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j)
            vis[j] = conn[j] = 0, G[j].clear();
        dfs(i, r);
        while (!stk.empty()) {
            int clr = stk.back();
            stk.pop_back();
            for (pii e : road[clr]) {
                if (conn[e.X] && conn[e.Y])
                    continue;
                if (conn[e.X] || conn[e.Y]) {
                    if (!conn[e.X])
                        dfs(e.X, r);
                    if (!conn[e.Y])
                        dfs(e.Y, r);
                    continue;
                }
                G[e.X].pb(e.Y);
                G[e.Y].pb(e.X);
            }
        }
        for (int j = 0; j < n; ++j)
            arr[i] += conn[j];
    }
    int mi = *min_element(ALL(arr));
    for (int i = 0; i < n; ++i)
        if (arr[i] == mi)
            ans[i] = 1;
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14284 KB Output is correct
2 Correct 8 ms 14304 KB Output is correct
3 Correct 8 ms 14332 KB Output is correct
4 Correct 9 ms 14284 KB Output is correct
5 Correct 8 ms 14284 KB Output is correct
6 Correct 8 ms 14364 KB Output is correct
7 Correct 9 ms 14280 KB Output is correct
8 Correct 9 ms 14284 KB Output is correct
9 Correct 9 ms 14284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14284 KB Output is correct
2 Correct 8 ms 14304 KB Output is correct
3 Correct 8 ms 14332 KB Output is correct
4 Correct 9 ms 14284 KB Output is correct
5 Correct 8 ms 14284 KB Output is correct
6 Correct 8 ms 14364 KB Output is correct
7 Correct 9 ms 14280 KB Output is correct
8 Correct 9 ms 14284 KB Output is correct
9 Correct 9 ms 14284 KB Output is correct
10 Correct 8 ms 14284 KB Output is correct
11 Correct 9 ms 14404 KB Output is correct
12 Correct 8 ms 14340 KB Output is correct
13 Correct 8 ms 14284 KB Output is correct
14 Correct 9 ms 14396 KB Output is correct
15 Correct 9 ms 14284 KB Output is correct
16 Correct 9 ms 14284 KB Output is correct
17 Correct 8 ms 14336 KB Output is correct
18 Correct 9 ms 14284 KB Output is correct
19 Correct 8 ms 14296 KB Output is correct
20 Correct 9 ms 14284 KB Output is correct
21 Correct 9 ms 14412 KB Output is correct
22 Correct 9 ms 14300 KB Output is correct
23 Correct 9 ms 14412 KB Output is correct
24 Correct 9 ms 14412 KB Output is correct
25 Correct 10 ms 14364 KB Output is correct
26 Correct 9 ms 14412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14284 KB Output is correct
2 Correct 8 ms 14304 KB Output is correct
3 Correct 8 ms 14332 KB Output is correct
4 Correct 9 ms 14284 KB Output is correct
5 Correct 8 ms 14284 KB Output is correct
6 Correct 8 ms 14364 KB Output is correct
7 Correct 9 ms 14280 KB Output is correct
8 Correct 9 ms 14284 KB Output is correct
9 Correct 9 ms 14284 KB Output is correct
10 Correct 8 ms 14284 KB Output is correct
11 Correct 9 ms 14404 KB Output is correct
12 Correct 8 ms 14340 KB Output is correct
13 Correct 8 ms 14284 KB Output is correct
14 Correct 9 ms 14396 KB Output is correct
15 Correct 9 ms 14284 KB Output is correct
16 Correct 9 ms 14284 KB Output is correct
17 Correct 8 ms 14336 KB Output is correct
18 Correct 9 ms 14284 KB Output is correct
19 Correct 8 ms 14296 KB Output is correct
20 Correct 9 ms 14284 KB Output is correct
21 Correct 9 ms 14412 KB Output is correct
22 Correct 9 ms 14300 KB Output is correct
23 Correct 9 ms 14412 KB Output is correct
24 Correct 9 ms 14412 KB Output is correct
25 Correct 10 ms 14364 KB Output is correct
26 Correct 9 ms 14412 KB Output is correct
27 Correct 56 ms 14592 KB Output is correct
28 Correct 55 ms 14540 KB Output is correct
29 Correct 56 ms 14540 KB Output is correct
30 Correct 24 ms 14540 KB Output is correct
31 Correct 12 ms 14412 KB Output is correct
32 Correct 11 ms 14412 KB Output is correct
33 Correct 15 ms 14412 KB Output is correct
34 Correct 29 ms 14440 KB Output is correct
35 Correct 29 ms 14488 KB Output is correct
36 Correct 90 ms 14532 KB Output is correct
37 Correct 91 ms 14532 KB Output is correct
38 Correct 156 ms 14660 KB Output is correct
39 Correct 142 ms 14540 KB Output is correct
40 Correct 25 ms 14400 KB Output is correct
41 Correct 49 ms 14544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14284 KB Output is correct
2 Correct 8 ms 14304 KB Output is correct
3 Correct 8 ms 14332 KB Output is correct
4 Correct 9 ms 14284 KB Output is correct
5 Correct 8 ms 14284 KB Output is correct
6 Correct 8 ms 14364 KB Output is correct
7 Correct 9 ms 14280 KB Output is correct
8 Correct 9 ms 14284 KB Output is correct
9 Correct 9 ms 14284 KB Output is correct
10 Execution timed out 3060 ms 33188 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14284 KB Output is correct
2 Correct 8 ms 14304 KB Output is correct
3 Correct 8 ms 14332 KB Output is correct
4 Correct 9 ms 14284 KB Output is correct
5 Correct 8 ms 14284 KB Output is correct
6 Correct 8 ms 14364 KB Output is correct
7 Correct 9 ms 14280 KB Output is correct
8 Correct 9 ms 14284 KB Output is correct
9 Correct 9 ms 14284 KB Output is correct
10 Correct 8 ms 14284 KB Output is correct
11 Correct 9 ms 14404 KB Output is correct
12 Correct 8 ms 14340 KB Output is correct
13 Correct 8 ms 14284 KB Output is correct
14 Correct 9 ms 14396 KB Output is correct
15 Correct 9 ms 14284 KB Output is correct
16 Correct 9 ms 14284 KB Output is correct
17 Correct 8 ms 14336 KB Output is correct
18 Correct 9 ms 14284 KB Output is correct
19 Correct 8 ms 14296 KB Output is correct
20 Correct 9 ms 14284 KB Output is correct
21 Correct 9 ms 14412 KB Output is correct
22 Correct 9 ms 14300 KB Output is correct
23 Correct 9 ms 14412 KB Output is correct
24 Correct 9 ms 14412 KB Output is correct
25 Correct 10 ms 14364 KB Output is correct
26 Correct 9 ms 14412 KB Output is correct
27 Correct 56 ms 14592 KB Output is correct
28 Correct 55 ms 14540 KB Output is correct
29 Correct 56 ms 14540 KB Output is correct
30 Correct 24 ms 14540 KB Output is correct
31 Correct 12 ms 14412 KB Output is correct
32 Correct 11 ms 14412 KB Output is correct
33 Correct 15 ms 14412 KB Output is correct
34 Correct 29 ms 14440 KB Output is correct
35 Correct 29 ms 14488 KB Output is correct
36 Correct 90 ms 14532 KB Output is correct
37 Correct 91 ms 14532 KB Output is correct
38 Correct 156 ms 14660 KB Output is correct
39 Correct 142 ms 14540 KB Output is correct
40 Correct 25 ms 14400 KB Output is correct
41 Correct 49 ms 14544 KB Output is correct
42 Execution timed out 3060 ms 33188 KB Time limit exceeded
43 Halted 0 ms 0 KB -