# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
721966 | 2023-04-11T09:28:38 Z | danikoynov | Connecting Supertrees (IOI20_supertrees) | C++14 | 187 ms | 30080 KB |
#include "supertrees.h" #include <bits/stdc++.h> using namespace std; const int maxn = 1010; vector < int > graph[maxn], graph2[maxn], comp; int cap[maxn][maxn]; int used[maxn], N; vector<std::vector<int>> answer; void dfs2(int v) { comp.push_back(v); used[v] = 1; for (int u : graph2[v]) { if (!used[u]) dfs2(u); } } void dfs(int v) { comp.push_back(v); used[v] = 1; for (int u : graph[v]) { if (!used[u]) dfs(u); } } bool solve_2_component() { /**for (int i = 0; i < comp.size(); i ++) for (int j = 0; j < comp.size(); j ++) if (cap[comp[i]][comp[j]] != 2) return false; if (comp.size() == 2) return false;*/ if (comp.size() == 1) return true; answer[comp[0]][comp.back()] = 1; answer[comp.back()][comp[0]] = 1; for (int i = 0; i < (int)(comp.size()) - 1; i ++) { answer[comp[i]][comp[i + 1]] = 1; answer[comp[i + 1]][comp[i]] = 1; } /**for (int i = 0; i < comp.size(); i ++) for (int j = 0; j < comp.size(); j ++) cap[comp[i]][comp[j]] = 0;*/ return true; } bool solve_component() { for (int i = 0; i < comp.size(); i ++) for (int j = 0; j < comp.size(); j ++) if (cap[comp[i]][comp[j]] == 0) return false; /**if (comp.size() != 1) { if (cap[comp[0]][comp[1]] == 2) { if (comp.size() == 2) return false; answer[comp[0]][comp.back()] = 1; answer[comp.back()][comp[0]] = 1; } }*/ for (int i = 0; i < (int)(comp.size()) - 1; i ++) { answer[comp[i]][comp[i + 1]] = 1; answer[comp[i + 1]][comp[i]] = 1; } for (int i = 1; i < comp.size(); i ++) for (int j = 0; j < N; j ++) if (cap[comp[i]][j] == 2) { cap[comp[i]][j] = 0; cap[j][comp[i]] = 0; } return true; } int construct(std::vector<std::vector<int>> p) { int n = p.size(); N = n; bool all2 = true; for (int i = 0; i < n; i++) { std::vector<int> row; row.resize(n, 0); answer.push_back(row); } for (int i = 0; i < n; i ++) for (int j = 0; j < n; j ++) { if (p[i][j] == 1) all2 = false; cap[i][j] = p[i][j]; } for (int i = 0; i < n; i ++) for (int j = 0; j < n; j ++) { if (i != j && (cap[i][j] == 1 || (cap[i][j] == 2 && all2))) graph[i].push_back(j); } for (int i = 0; i < n; i ++) { if (!used[i]) { comp.clear(); dfs(i); bool is_fine = solve_component(); if (!is_fine) return 0; } } memset(used, 0, sizeof(used)); for (int i = 0; i < n; i ++) for (int j = 0; j < n; j ++) { if (i != j && cap[i][j] == 2) graph2[i].push_back(j); } for (int i = 0; i < n; i ++) { if (!used[i]) { comp.clear(); dfs2(i); bool is_fine = solve_2_component(); if (!is_fine) return false; } } build(answer); return 1; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 0 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 8 ms | 2224 KB | Output is correct |
7 | Correct | 175 ms | 30080 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 0 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 8 ms | 2224 KB | Output is correct |
7 | Correct | 175 ms | 30080 KB | Output is correct |
8 | Correct | 0 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 340 KB | Output is correct |
11 | Correct | 1 ms | 340 KB | Output is correct |
12 | Correct | 7 ms | 2044 KB | Output is correct |
13 | Correct | 169 ms | 26040 KB | Output is correct |
14 | Correct | 0 ms | 340 KB | Output is correct |
15 | Correct | 0 ms | 340 KB | Output is correct |
16 | Correct | 5 ms | 1748 KB | Output is correct |
17 | Correct | 83 ms | 18508 KB | Output is correct |
18 | Correct | 0 ms | 340 KB | Output is correct |
19 | Correct | 1 ms | 340 KB | Output is correct |
20 | Correct | 45 ms | 7796 KB | Output is correct |
21 | Correct | 177 ms | 26536 KB | Output is correct |
22 | Correct | 173 ms | 26040 KB | Output is correct |
23 | Correct | 181 ms | 28092 KB | Output is correct |
24 | Correct | 162 ms | 26040 KB | Output is correct |
25 | Correct | 73 ms | 16632 KB | Output is correct |
26 | Correct | 71 ms | 16076 KB | Output is correct |
27 | Correct | 187 ms | 29116 KB | Output is correct |
28 | Correct | 167 ms | 26044 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 0 ms | 340 KB | Output is correct |
4 | Incorrect | 0 ms | 340 KB | Answer gives possible 1 while actual possible 0 |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 44 ms | 7736 KB | Output is correct |
5 | Correct | 186 ms | 26496 KB | Output is correct |
6 | Correct | 169 ms | 26036 KB | Output is correct |
7 | Correct | 187 ms | 28088 KB | Output is correct |
8 | Correct | 0 ms | 340 KB | Output is correct |
9 | Correct | 44 ms | 7812 KB | Output is correct |
10 | Correct | 177 ms | 26556 KB | Output is correct |
11 | Correct | 164 ms | 25992 KB | Output is correct |
12 | Correct | 176 ms | 29028 KB | Output is correct |
13 | Correct | 0 ms | 340 KB | Output is correct |
14 | Correct | 0 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 340 KB | Output is correct |
16 | Correct | 42 ms | 7752 KB | Output is correct |
17 | Correct | 169 ms | 26568 KB | Output is correct |
18 | Correct | 175 ms | 26288 KB | Output is correct |
19 | Correct | 165 ms | 26184 KB | Output is correct |
20 | Correct | 171 ms | 25936 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 0 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 8 ms | 2224 KB | Output is correct |
7 | Correct | 175 ms | 30080 KB | Output is correct |
8 | Correct | 0 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 340 KB | Output is correct |
11 | Correct | 1 ms | 340 KB | Output is correct |
12 | Correct | 7 ms | 2044 KB | Output is correct |
13 | Correct | 169 ms | 26040 KB | Output is correct |
14 | Correct | 0 ms | 340 KB | Output is correct |
15 | Correct | 0 ms | 340 KB | Output is correct |
16 | Correct | 5 ms | 1748 KB | Output is correct |
17 | Correct | 83 ms | 18508 KB | Output is correct |
18 | Correct | 0 ms | 340 KB | Output is correct |
19 | Correct | 1 ms | 340 KB | Output is correct |
20 | Correct | 45 ms | 7796 KB | Output is correct |
21 | Correct | 177 ms | 26536 KB | Output is correct |
22 | Correct | 173 ms | 26040 KB | Output is correct |
23 | Correct | 181 ms | 28092 KB | Output is correct |
24 | Correct | 162 ms | 26040 KB | Output is correct |
25 | Correct | 73 ms | 16632 KB | Output is correct |
26 | Correct | 71 ms | 16076 KB | Output is correct |
27 | Correct | 187 ms | 29116 KB | Output is correct |
28 | Correct | 167 ms | 26044 KB | Output is correct |
29 | Correct | 1 ms | 340 KB | Output is correct |
30 | Correct | 1 ms | 340 KB | Output is correct |
31 | Correct | 0 ms | 340 KB | Output is correct |
32 | Incorrect | 0 ms | 340 KB | Answer gives possible 1 while actual possible 0 |
33 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 0 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 8 ms | 2224 KB | Output is correct |
7 | Correct | 175 ms | 30080 KB | Output is correct |
8 | Correct | 0 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 340 KB | Output is correct |
11 | Correct | 1 ms | 340 KB | Output is correct |
12 | Correct | 7 ms | 2044 KB | Output is correct |
13 | Correct | 169 ms | 26040 KB | Output is correct |
14 | Correct | 0 ms | 340 KB | Output is correct |
15 | Correct | 0 ms | 340 KB | Output is correct |
16 | Correct | 5 ms | 1748 KB | Output is correct |
17 | Correct | 83 ms | 18508 KB | Output is correct |
18 | Correct | 0 ms | 340 KB | Output is correct |
19 | Correct | 1 ms | 340 KB | Output is correct |
20 | Correct | 45 ms | 7796 KB | Output is correct |
21 | Correct | 177 ms | 26536 KB | Output is correct |
22 | Correct | 173 ms | 26040 KB | Output is correct |
23 | Correct | 181 ms | 28092 KB | Output is correct |
24 | Correct | 162 ms | 26040 KB | Output is correct |
25 | Correct | 73 ms | 16632 KB | Output is correct |
26 | Correct | 71 ms | 16076 KB | Output is correct |
27 | Correct | 187 ms | 29116 KB | Output is correct |
28 | Correct | 167 ms | 26044 KB | Output is correct |
29 | Correct | 1 ms | 340 KB | Output is correct |
30 | Correct | 1 ms | 340 KB | Output is correct |
31 | Correct | 0 ms | 340 KB | Output is correct |
32 | Incorrect | 0 ms | 340 KB | Answer gives possible 1 while actual possible 0 |
33 | Halted | 0 ms | 0 KB | - |