# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
812695 | 2023-08-07T10:15:24 Z | KemalK | Connecting Supertrees (IOI20_supertrees) | C++17 | 179 ms | 24064 KB |
#include "supertrees.h" #include <vector> #include <bits/stdc++.h> using namespace std; const int N = 1e3 + 5; int pr[N]; int sz[N]; int get(int x){ if (pr[x] == x){ return x; } return (pr[x] = get(pr[x])); } void unit(int a, int b){ a = get(a); b = get(b); if (a != b){ if (sz[a] < sz[b]){ swap(a, b); } pr[b] = a; sz[a] += sz[b]; } } int construct(std::vector<std::vector<int>> p) { int n = p.size(); for (int i = 0; i < n; i++){ pr[i] = i; sz[i] = 1; } int check = 0; for (int i = 0; i < n; i++){ for (int j = 0; j < n; j++){ if (p[i][j]){ unit(i, j); check = p[i][j]; } } } for (int i = 0; i < n; i++){ for (int j = 0; j < n; j++){ if (p[i][j] == 0 and get(i) == get(j)){ //impossible return 0; } } } vector <vector<int>> answer(n, vector<int>(n)); if(!check){ build(answer); return 1; } for (int i = 0; i < n; i++){ vector <int> branch; for (int j = 0; j < n; j++){ if (get(j) == i){ branch.push_back(j); } } for (int j = 0; j + 1 < branch.size(); j++){ answer[branch[j]][branch[j + 1]] = 1; answer[branch[j + 1]][branch[j]] = 1; } if (check == 2){ if(branch.size() == 2){ return 0; } if (branch.size() > 2){ answer[branch[0]][branch.back()] = 1; answer[branch.back()][branch[0]] = 1; } } } build(answer); return 1; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 7 ms | 1208 KB | Output is correct |
7 | Correct | 161 ms | 23944 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 7 ms | 1208 KB | Output is correct |
7 | Correct | 161 ms | 23944 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 300 KB | Output is correct |
10 | Correct | 0 ms | 212 KB | Output is correct |
11 | Correct | 0 ms | 256 KB | Output is correct |
12 | Correct | 7 ms | 1200 KB | Output is correct |
13 | Correct | 159 ms | 23924 KB | Output is correct |
14 | Correct | 0 ms | 212 KB | Output is correct |
15 | Correct | 0 ms | 212 KB | Output is correct |
16 | Correct | 4 ms | 596 KB | Output is correct |
17 | Correct | 74 ms | 10104 KB | Output is correct |
18 | Correct | 0 ms | 212 KB | Output is correct |
19 | Correct | 0 ms | 212 KB | Output is correct |
20 | Correct | 40 ms | 6148 KB | Output is correct |
21 | Correct | 159 ms | 24012 KB | Output is correct |
22 | Correct | 158 ms | 23944 KB | Output is correct |
23 | Correct | 168 ms | 24064 KB | Output is correct |
24 | Correct | 166 ms | 23964 KB | Output is correct |
25 | Correct | 71 ms | 10116 KB | Output is correct |
26 | Correct | 64 ms | 10100 KB | Output is correct |
27 | Correct | 179 ms | 23928 KB | Output is correct |
28 | Correct | 171 ms | 23936 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Incorrect | 0 ms | 212 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 | 212 KB | Output is correct |
2 | Incorrect | 0 ms | 212 KB | Too few ways to get from 0 to 1, should be 2 found 1 |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 7 ms | 1208 KB | Output is correct |
7 | Correct | 161 ms | 23944 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 300 KB | Output is correct |
10 | Correct | 0 ms | 212 KB | Output is correct |
11 | Correct | 0 ms | 256 KB | Output is correct |
12 | Correct | 7 ms | 1200 KB | Output is correct |
13 | Correct | 159 ms | 23924 KB | Output is correct |
14 | Correct | 0 ms | 212 KB | Output is correct |
15 | Correct | 0 ms | 212 KB | Output is correct |
16 | Correct | 4 ms | 596 KB | Output is correct |
17 | Correct | 74 ms | 10104 KB | Output is correct |
18 | Correct | 0 ms | 212 KB | Output is correct |
19 | Correct | 0 ms | 212 KB | Output is correct |
20 | Correct | 40 ms | 6148 KB | Output is correct |
21 | Correct | 159 ms | 24012 KB | Output is correct |
22 | Correct | 158 ms | 23944 KB | Output is correct |
23 | Correct | 168 ms | 24064 KB | Output is correct |
24 | Correct | 166 ms | 23964 KB | Output is correct |
25 | Correct | 71 ms | 10116 KB | Output is correct |
26 | Correct | 64 ms | 10100 KB | Output is correct |
27 | Correct | 179 ms | 23928 KB | Output is correct |
28 | Correct | 171 ms | 23936 KB | Output is correct |
29 | Correct | 0 ms | 212 KB | Output is correct |
30 | Correct | 0 ms | 212 KB | Output is correct |
31 | Correct | 0 ms | 212 KB | Output is correct |
32 | Incorrect | 0 ms | 212 KB | Answer gives possible 1 while actual possible 0 |
33 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 7 ms | 1208 KB | Output is correct |
7 | Correct | 161 ms | 23944 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 300 KB | Output is correct |
10 | Correct | 0 ms | 212 KB | Output is correct |
11 | Correct | 0 ms | 256 KB | Output is correct |
12 | Correct | 7 ms | 1200 KB | Output is correct |
13 | Correct | 159 ms | 23924 KB | Output is correct |
14 | Correct | 0 ms | 212 KB | Output is correct |
15 | Correct | 0 ms | 212 KB | Output is correct |
16 | Correct | 4 ms | 596 KB | Output is correct |
17 | Correct | 74 ms | 10104 KB | Output is correct |
18 | Correct | 0 ms | 212 KB | Output is correct |
19 | Correct | 0 ms | 212 KB | Output is correct |
20 | Correct | 40 ms | 6148 KB | Output is correct |
21 | Correct | 159 ms | 24012 KB | Output is correct |
22 | Correct | 158 ms | 23944 KB | Output is correct |
23 | Correct | 168 ms | 24064 KB | Output is correct |
24 | Correct | 166 ms | 23964 KB | Output is correct |
25 | Correct | 71 ms | 10116 KB | Output is correct |
26 | Correct | 64 ms | 10100 KB | Output is correct |
27 | Correct | 179 ms | 23928 KB | Output is correct |
28 | Correct | 171 ms | 23936 KB | Output is correct |
29 | Correct | 0 ms | 212 KB | Output is correct |
30 | Correct | 0 ms | 212 KB | Output is correct |
31 | Correct | 0 ms | 212 KB | Output is correct |
32 | Incorrect | 0 ms | 212 KB | Answer gives possible 1 while actual possible 0 |
33 | Halted | 0 ms | 0 KB | - |