Submission #419442

# Submission time Handle Problem Language Result Execution time Memory
419442 2021-06-07T06:42:30 Z vkgainz Connecting Supertrees (IOI20_supertrees) C++17
100 / 100
283 ms 32120 KB
#include <bits/stdc++.h>
using namespace std;


void build(vector<vector<int>> b);


int construct(vector<vector<int>> p) {
    int n = (int) p.size();
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            if(p[i][j] == 3) return 0;
            if(p[i][j] != p[j][i]) return 0;
        }
    }

    vector<vector<int>> put(n, vector<int>(n));
    vector<bool> vis(n);
    vector<int> id(n);
    vector<vector<int>> store(n);
    for(int x = 0; x < n; x++) {
        if(vis[x]) continue;
        queue<int> q;
        vector<int> f;
        q.push(x);
        vis[x] = true;
        while(!q.empty()) {
            auto curr = q.front();
            f.push_back(curr);
            q.pop();
            for(int next = 0; next < n; next++) {
                if(p[curr][next] == 0) continue;

                if(p[curr][next] == 1) {
                    if(!vis[next]) {
                        vis[next] = true;
                        q.push(next);
                    }
                }
            }
        }

        for(int i = 0; i < (int) f.size(); i++) {
            for(int j = i + 1; j < (int) f.size(); j++) {
                if(p[f[i]][f[j]] != 1) return 0;
            }
        }
        for(int i = 0; i < (int) f.size() - 1; i++) {
            put[f[i]][f[i + 1]] = 1, put[f[i + 1]][f[i]] = 1;
        }
        store[x] = f;
        for(int i = 0; i < (int) f.size(); i++) {
            id[f[i]] = x;
        }
    }
    vis.clear(), vis.resize(n, 0);
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            bool zer = false, two = false;
            for(int x : store[i]) {
                for(int y : store[j]) {
                    if(p[x][y] == 0) zer = true;
                    if(p[x][y] == 2) two = true;
                }
            }
            if(zer && two) return 0;
        }
    }
    
    vector<vector<int>> adj(n);
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            if(store[i].empty() || store[j].empty()) continue;
            if(p[i][j] == 2) adj[i].push_back(j), adj[j].push_back(i);
        }
    }
    for(int i = 0; i < n; i++) {
        if(vis[i] || store[i].empty()) continue;
        queue<int> q;
        q.push(i);
        vis[i] = true;
        vector<int> in;
        while(!q.empty()) {
            auto curr = q.front();
            q.pop();
            in.push_back(curr);
            for(int next : adj[curr]) {
                if(!vis[next]) {
                    vis[next] = true;
                    q.push(next);
                }
            }
        }
        for(int a = 0; a < (int) in.size(); a++) {
            for(int b = 0; b < (int) in.size(); b++) {
                if(p[in[a]][in[b]] == 0) return 0;
            }
        }
        if(in.size() == 2) return 0;
        if(in.size() == 1) continue;
        for(int j = 0; j < (int) in.size(); j++) {
            put[in[j]][in[(j + 1) % in.size()]] = 1, put[in[(j + 1) % in.size()]][in[j]] = 1;
        }
    }
    build(put);
    return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 11 ms 1204 KB Output is correct
7 Correct 260 ms 23964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 11 ms 1204 KB Output is correct
7 Correct 260 ms 23964 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 288 KB Output is correct
12 Correct 10 ms 1228 KB Output is correct
13 Correct 242 ms 23988 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 5 ms 788 KB Output is correct
17 Correct 113 ms 14064 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 60 ms 6236 KB Output is correct
21 Correct 245 ms 23964 KB Output is correct
22 Correct 241 ms 23948 KB Output is correct
23 Correct 250 ms 24052 KB Output is correct
24 Correct 240 ms 24052 KB Output is correct
25 Correct 99 ms 14112 KB Output is correct
26 Correct 95 ms 14072 KB Output is correct
27 Correct 250 ms 24036 KB Output is correct
28 Correct 241 ms 24044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 10 ms 1256 KB Output is correct
9 Correct 256 ms 23996 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 11 ms 1612 KB Output is correct
13 Correct 254 ms 32120 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 6 ms 1036 KB Output is correct
17 Correct 137 ms 19780 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 63 ms 6312 KB Output is correct
22 Correct 283 ms 25152 KB Output is correct
23 Correct 244 ms 24064 KB Output is correct
24 Correct 259 ms 30232 KB Output is correct
25 Correct 107 ms 14148 KB Output is correct
26 Correct 112 ms 15208 KB Output is correct
27 Correct 237 ms 24064 KB Output is correct
28 Correct 265 ms 28144 KB Output is correct
29 Correct 106 ms 14148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 244 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 59 ms 6256 KB Output is correct
5 Correct 244 ms 23792 KB Output is correct
6 Correct 239 ms 23876 KB Output is correct
7 Correct 253 ms 24004 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 59 ms 6384 KB Output is correct
10 Correct 251 ms 24640 KB Output is correct
11 Correct 248 ms 23628 KB Output is correct
12 Correct 274 ms 29764 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 60 ms 6268 KB Output is correct
17 Correct 253 ms 25156 KB Output is correct
18 Correct 277 ms 24552 KB Output is correct
19 Correct 239 ms 24260 KB Output is correct
20 Correct 236 ms 24032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 11 ms 1204 KB Output is correct
7 Correct 260 ms 23964 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 288 KB Output is correct
12 Correct 10 ms 1228 KB Output is correct
13 Correct 242 ms 23988 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 5 ms 788 KB Output is correct
17 Correct 113 ms 14064 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 60 ms 6236 KB Output is correct
21 Correct 245 ms 23964 KB Output is correct
22 Correct 241 ms 23948 KB Output is correct
23 Correct 250 ms 24052 KB Output is correct
24 Correct 240 ms 24052 KB Output is correct
25 Correct 99 ms 14112 KB Output is correct
26 Correct 95 ms 14072 KB Output is correct
27 Correct 250 ms 24036 KB Output is correct
28 Correct 241 ms 24044 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 10 ms 1256 KB Output is correct
37 Correct 256 ms 23996 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 11 ms 1612 KB Output is correct
41 Correct 254 ms 32120 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 6 ms 1036 KB Output is correct
45 Correct 137 ms 19780 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 0 ms 204 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 63 ms 6312 KB Output is correct
50 Correct 283 ms 25152 KB Output is correct
51 Correct 244 ms 24064 KB Output is correct
52 Correct 259 ms 30232 KB Output is correct
53 Correct 107 ms 14148 KB Output is correct
54 Correct 112 ms 15208 KB Output is correct
55 Correct 237 ms 24064 KB Output is correct
56 Correct 265 ms 28144 KB Output is correct
57 Correct 106 ms 14148 KB Output is correct
58 Correct 0 ms 204 KB Output is correct
59 Correct 1 ms 204 KB Output is correct
60 Correct 7 ms 844 KB Output is correct
61 Correct 113 ms 14064 KB Output is correct
62 Correct 1 ms 204 KB Output is correct
63 Correct 1 ms 204 KB Output is correct
64 Correct 1 ms 204 KB Output is correct
65 Correct 61 ms 6340 KB Output is correct
66 Correct 99 ms 14060 KB Output is correct
67 Correct 98 ms 14072 KB Output is correct
68 Correct 109 ms 14068 KB Output is correct
69 Correct 129 ms 14060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 11 ms 1204 KB Output is correct
7 Correct 260 ms 23964 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 288 KB Output is correct
12 Correct 10 ms 1228 KB Output is correct
13 Correct 242 ms 23988 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 5 ms 788 KB Output is correct
17 Correct 113 ms 14064 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 60 ms 6236 KB Output is correct
21 Correct 245 ms 23964 KB Output is correct
22 Correct 241 ms 23948 KB Output is correct
23 Correct 250 ms 24052 KB Output is correct
24 Correct 240 ms 24052 KB Output is correct
25 Correct 99 ms 14112 KB Output is correct
26 Correct 95 ms 14072 KB Output is correct
27 Correct 250 ms 24036 KB Output is correct
28 Correct 241 ms 24044 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 10 ms 1256 KB Output is correct
37 Correct 256 ms 23996 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 11 ms 1612 KB Output is correct
41 Correct 254 ms 32120 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 6 ms 1036 KB Output is correct
45 Correct 137 ms 19780 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 0 ms 204 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 63 ms 6312 KB Output is correct
50 Correct 283 ms 25152 KB Output is correct
51 Correct 244 ms 24064 KB Output is correct
52 Correct 259 ms 30232 KB Output is correct
53 Correct 107 ms 14148 KB Output is correct
54 Correct 112 ms 15208 KB Output is correct
55 Correct 237 ms 24064 KB Output is correct
56 Correct 265 ms 28144 KB Output is correct
57 Correct 106 ms 14148 KB Output is correct
58 Correct 1 ms 204 KB Output is correct
59 Correct 1 ms 244 KB Output is correct
60 Correct 1 ms 204 KB Output is correct
61 Correct 59 ms 6256 KB Output is correct
62 Correct 244 ms 23792 KB Output is correct
63 Correct 239 ms 23876 KB Output is correct
64 Correct 253 ms 24004 KB Output is correct
65 Correct 1 ms 204 KB Output is correct
66 Correct 59 ms 6384 KB Output is correct
67 Correct 251 ms 24640 KB Output is correct
68 Correct 248 ms 23628 KB Output is correct
69 Correct 274 ms 29764 KB Output is correct
70 Correct 1 ms 204 KB Output is correct
71 Correct 1 ms 204 KB Output is correct
72 Correct 1 ms 204 KB Output is correct
73 Correct 60 ms 6268 KB Output is correct
74 Correct 253 ms 25156 KB Output is correct
75 Correct 277 ms 24552 KB Output is correct
76 Correct 239 ms 24260 KB Output is correct
77 Correct 236 ms 24032 KB Output is correct
78 Correct 0 ms 204 KB Output is correct
79 Correct 1 ms 204 KB Output is correct
80 Correct 7 ms 844 KB Output is correct
81 Correct 113 ms 14064 KB Output is correct
82 Correct 1 ms 204 KB Output is correct
83 Correct 1 ms 204 KB Output is correct
84 Correct 1 ms 204 KB Output is correct
85 Correct 61 ms 6340 KB Output is correct
86 Correct 99 ms 14060 KB Output is correct
87 Correct 98 ms 14072 KB Output is correct
88 Correct 109 ms 14068 KB Output is correct
89 Correct 129 ms 14060 KB Output is correct
90 Correct 1 ms 288 KB Output is correct
91 Correct 1 ms 204 KB Output is correct
92 Correct 4 ms 588 KB Output is correct
93 Correct 96 ms 10100 KB Output is correct
94 Correct 1 ms 204 KB Output is correct
95 Correct 1 ms 204 KB Output is correct
96 Correct 1 ms 204 KB Output is correct
97 Correct 24 ms 2672 KB Output is correct
98 Correct 97 ms 10052 KB Output is correct
99 Correct 95 ms 10092 KB Output is correct
100 Correct 99 ms 10016 KB Output is correct
101 Correct 91 ms 10016 KB Output is correct
102 Correct 91 ms 10016 KB Output is correct
103 Correct 97 ms 10100 KB Output is correct
104 Correct 95 ms 10104 KB Output is correct
105 Correct 106 ms 10104 KB Output is correct