Submission #1058767

# Submission time Handle Problem Language Result Execution time Memory
1058767 2024-08-14T13:30:26 Z qwusha Keys (IOI21_keys) C++17
37 / 100
3000 ms 34476 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
typedef long double ld;
const ld eps = 1e-8;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const ll inf = 1e18;
const ll mod = 1e9 + 7;

#include "keys.h"


vector<set<int>> g;
vector<vector<pair<int, int>>> gr;
vector<int> num;
int cnt = 0;

void dfs(int v, int number) {
    num[v] = number;
    cnt++;
    for (auto u : g[v]) {
        if (num[u] == -1) {
            dfs(u, number);
        }
    }
}

vector<int> find_reachable(vector<int> r, vector<int> fir, vector<int>sec, vector<int> c) {
    bool first = 1;
    int n = r.size();
    int m = fir.size();
    for (int i = 0; i < m; i++) {
        if (c[i] != 0)
            first = 0;
    }
    if (1) {
        gr.resize(n);
        for (int i = 0; i < m; i++) {
            gr[fir[i]].push_back({sec[i], c[i]});
            gr[sec[i]].push_back({fir[i], c[i]});
        }
        vector<int> p(n);
        for (int i = 0; i < n; i++) {
            set<int> keys = {r[i]};
            set<int> pos = {i};
            vector<int> used(n, 0);
            vector<set<int>> reach(n);
            while (!pos.empty()) {
                auto v = *pos.begin();
                pos.erase(pos.begin());
                if (used[v])
                    continue;
                p[i]++;
                used[v] = 1;
                if (keys.find(r[v]) == keys.end()) {
                    keys.insert(r[v]);
                    for (auto nod : reach[r[v]]) {
                        if (!used[nod])
                            pos.insert(nod);
                    }
                }
                for (auto [u, w] : gr[v]) {
                    if (!used[u]) {
                        if (keys.find(w) != keys.end()) {
                            pos.insert(u);
                        } else {
                            reach[w].insert(u);
                        }
                    }
                }
            }
        }
        int mini = n + 1;
        for (int i = 0; i < n; i++) {
            mini = min(mini, p[i]);
        }
        vector<int> res(n);
        for (int i = 0; i < n; i++) {
            if (p[i] == mini)
                res[i] = 1;
        }
        return res;
    }
    g.resize(n);
    for (int i = 0; i < m; i++) {
        g[fir[i]].insert(sec[i]);
        g[sec[i]].insert(fir[i]);
    }
    vector<int> res(n);
    bool nonzer = 0;
    for (int i = 0; i < n; i++) {
        if (r[i] != 0)
            nonzer = 1;
    }
    num.resize(n, -1);
    vector<int> sz;
    int mini = n + 1;
    for (int i = 0; i < n; i++) {
        if (num[i] == -1) {
            cnt = 0;
            dfs(i, sz.size());
            sz.push_back(cnt);
            mini = min(mini, cnt);
        }
    }
    for (int i = 0; i < n; i++) {
        if (nonzer) {
            if (r[i] != 0 || sz[num[i]] == 1) {
                res[i] = 1;
            }
        } else {
            if (sz[num[i]] == mini) {
                res[i] = 1;
            }
        }
    }
    return res;
}

/*
int main() {
    vector<int> r = {0, 1, 1, 2, 2, 1, 2},
    u = {0, 0, 1, 1, 2, 3, 3, 4, 4, 5},
    v = {1, 2, 2, 3, 3, 4, 5, 5, 6, 6},
    c = {0, 0, 1, 0, 0, 1, 2, 0, 2, 1};

    auto res = find_reachable(r,u,v,c);
    for (int i = 0; i < r.size(); i++) {
        cout << res[i] << ' ';
    }
}
*/



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:31:10: warning: variable 'first' set but not used [-Wunused-but-set-variable]
   31 |     bool first = 1;
      |          ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 360 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 360 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 2 ms 472 KB Output is correct
11 Correct 2 ms 480 KB Output is correct
12 Correct 2 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 3 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 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 2 ms 348 KB Output is correct
23 Correct 5 ms 348 KB Output is correct
24 Correct 4 ms 348 KB Output is correct
25 Correct 10 ms 348 KB Output is correct
26 Correct 7 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 360 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 2 ms 472 KB Output is correct
11 Correct 2 ms 480 KB Output is correct
12 Correct 2 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 3 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 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 2 ms 348 KB Output is correct
23 Correct 5 ms 348 KB Output is correct
24 Correct 4 ms 348 KB Output is correct
25 Correct 10 ms 348 KB Output is correct
26 Correct 7 ms 348 KB Output is correct
27 Correct 249 ms 1076 KB Output is correct
28 Correct 227 ms 860 KB Output is correct
29 Correct 226 ms 880 KB Output is correct
30 Correct 115 ms 600 KB Output is correct
31 Correct 3 ms 604 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 2 ms 348 KB Output is correct
34 Correct 71 ms 604 KB Output is correct
35 Correct 136 ms 604 KB Output is correct
36 Correct 575 ms 776 KB Output is correct
37 Correct 561 ms 600 KB Output is correct
38 Correct 769 ms 816 KB Output is correct
39 Correct 734 ms 600 KB Output is correct
40 Correct 20 ms 604 KB Output is correct
41 Correct 169 ms 644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 360 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Execution timed out 3030 ms 34476 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 360 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 2 ms 472 KB Output is correct
11 Correct 2 ms 480 KB Output is correct
12 Correct 2 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 3 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 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 2 ms 348 KB Output is correct
23 Correct 5 ms 348 KB Output is correct
24 Correct 4 ms 348 KB Output is correct
25 Correct 10 ms 348 KB Output is correct
26 Correct 7 ms 348 KB Output is correct
27 Correct 249 ms 1076 KB Output is correct
28 Correct 227 ms 860 KB Output is correct
29 Correct 226 ms 880 KB Output is correct
30 Correct 115 ms 600 KB Output is correct
31 Correct 3 ms 604 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 2 ms 348 KB Output is correct
34 Correct 71 ms 604 KB Output is correct
35 Correct 136 ms 604 KB Output is correct
36 Correct 575 ms 776 KB Output is correct
37 Correct 561 ms 600 KB Output is correct
38 Correct 769 ms 816 KB Output is correct
39 Correct 734 ms 600 KB Output is correct
40 Correct 20 ms 604 KB Output is correct
41 Correct 169 ms 644 KB Output is correct
42 Execution timed out 3030 ms 34476 KB Time limit exceeded
43 Halted 0 ms 0 KB -