# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
301441 | 2020-09-18T00:32:10 Z | qpwoeirut | Connecting Supertrees (IOI20_supertrees) | C++17 | 274 ms | 22268 KB |
#include "supertrees.h" #include <bits/stdc++.h> using namespace std; typedef vector<vector<int>> vvi; int N; int sub1(const vvi& p) { vvi ans(N, vector<int>(N)); for (int i=1; i<N; ++i) { ans[0][i] = 1; } build(ans); return 1; } const int MN = 1001; int root[MN]; int par(int u) { if (u == root[u]) return u; root[u] = par(root[u]); return root[u]; } void join(int u, int v) { if (par(u) == par(v)) return; root[u] = v; } bool dsu(const vvi& p) { for (int i=0; i<N; ++i) { root[i] = i; } for (int i=0; i<N; ++i) { for (int j=0; j<N; ++j) { if (p[i][j]) join(i, j); } } for (int i=0; i<N; ++i) { for (int j=0; j<N; ++j) { if (par(i) == par(j) && p[i][j] == 0) { return 0; } } } return 1; } int sub2(const vvi& p) { if (!dsu(p)) return 0; vvi ans(N, vector<int>(N)); for (int i=0; i<N; ++i) { if (i != par(i)) { ans[i][par(i)] = true; ans[par(i)][i] = true; } } build(ans); return 1; } int sub3(const vvi& p) { if (!dsu(p)) return 0; vvi ans(N, vector<int>(N)); vvi groups; for (int i=0; i<N; ++i) { if (i == par(i)) { vector<int> cur; for (int j=0; j<N; ++j) { if (i == par(j)) { cur.push_back(j); } } groups.push_back(cur); } } for (int i=0; i<groups.size(); ++i) { int gsz = groups[i].size(); for (int j=0; j<gsz; ++j) { ans[groups[i][(j+1) % gsz]][groups[i][j]] = ans[groups[i][j]][groups[i][(j+1) % gsz]] = 1; } } build(ans); return 1; } int construct(std::vector<std::vector<int>> p) { N = p.size(); set<int> vals; for (int i=0; i<N; ++i) { for (int j=0; j<N; ++j) { vals.insert(p[i][j]); } } //if (vals.size() == 1) { // if (vals.count(0)) { // vvi ans(N, vector<int>(N)); // build(ans); // return 1; // } // if (vals.count(1)) { // return sub1(p); // } //} if (vals.size() <= 2) { if (vals.count(1)) { return sub2(p); } if (vals.count(2)) { return sub3(p); } } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 256 KB | Output is correct |
2 | Correct | 0 ms | 256 KB | Output is correct |
3 | Correct | 0 ms | 256 KB | Output is correct |
4 | Correct | 0 ms | 256 KB | Output is correct |
5 | Correct | 0 ms | 256 KB | Output is correct |
6 | Correct | 11 ms | 1152 KB | Output is correct |
7 | Correct | 256 ms | 22136 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 256 KB | Output is correct |
2 | Correct | 0 ms | 256 KB | Output is correct |
3 | Correct | 0 ms | 256 KB | Output is correct |
4 | Correct | 0 ms | 256 KB | Output is correct |
5 | Correct | 0 ms | 256 KB | Output is correct |
6 | Correct | 11 ms | 1152 KB | Output is correct |
7 | Correct | 256 ms | 22136 KB | Output is correct |
8 | Correct | 0 ms | 256 KB | Output is correct |
9 | Correct | 0 ms | 256 KB | Output is correct |
10 | Correct | 0 ms | 256 KB | Output is correct |
11 | Correct | 0 ms | 256 KB | Output is correct |
12 | Correct | 13 ms | 1152 KB | Output is correct |
13 | Correct | 251 ms | 22136 KB | Output is correct |
14 | Correct | 0 ms | 256 KB | Output is correct |
15 | Correct | 0 ms | 256 KB | Output is correct |
16 | Correct | 6 ms | 640 KB | Output is correct |
17 | Correct | 130 ms | 8268 KB | Output is correct |
18 | Correct | 1 ms | 256 KB | Output is correct |
19 | Correct | 0 ms | 256 KB | Output is correct |
20 | Correct | 64 ms | 5752 KB | Output is correct |
21 | Correct | 257 ms | 22116 KB | Output is correct |
22 | Correct | 253 ms | 22108 KB | Output is correct |
23 | Correct | 274 ms | 22268 KB | Output is correct |
24 | Correct | 249 ms | 22136 KB | Output is correct |
25 | Incorrect | 255 ms | 22264 KB | Answer gives possible 1 while actual possible 0 |
26 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 256 KB | Output is correct |
3 | Correct | 0 ms | 256 KB | Output is correct |
4 | Incorrect | 0 ms | 256 KB | Answer gives possible 1 while actual possible 0 |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 256 KB | Output is correct |
2 | Incorrect | 1 ms | 256 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 | 256 KB | Output is correct |
2 | Correct | 0 ms | 256 KB | Output is correct |
3 | Correct | 0 ms | 256 KB | Output is correct |
4 | Correct | 0 ms | 256 KB | Output is correct |
5 | Correct | 0 ms | 256 KB | Output is correct |
6 | Correct | 11 ms | 1152 KB | Output is correct |
7 | Correct | 256 ms | 22136 KB | Output is correct |
8 | Correct | 0 ms | 256 KB | Output is correct |
9 | Correct | 0 ms | 256 KB | Output is correct |
10 | Correct | 0 ms | 256 KB | Output is correct |
11 | Correct | 0 ms | 256 KB | Output is correct |
12 | Correct | 13 ms | 1152 KB | Output is correct |
13 | Correct | 251 ms | 22136 KB | Output is correct |
14 | Correct | 0 ms | 256 KB | Output is correct |
15 | Correct | 0 ms | 256 KB | Output is correct |
16 | Correct | 6 ms | 640 KB | Output is correct |
17 | Correct | 130 ms | 8268 KB | Output is correct |
18 | Correct | 1 ms | 256 KB | Output is correct |
19 | Correct | 0 ms | 256 KB | Output is correct |
20 | Correct | 64 ms | 5752 KB | Output is correct |
21 | Correct | 257 ms | 22116 KB | Output is correct |
22 | Correct | 253 ms | 22108 KB | Output is correct |
23 | Correct | 274 ms | 22268 KB | Output is correct |
24 | Correct | 249 ms | 22136 KB | Output is correct |
25 | Incorrect | 255 ms | 22264 KB | Answer gives possible 1 while actual possible 0 |
26 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 256 KB | Output is correct |
2 | Correct | 0 ms | 256 KB | Output is correct |
3 | Correct | 0 ms | 256 KB | Output is correct |
4 | Correct | 0 ms | 256 KB | Output is correct |
5 | Correct | 0 ms | 256 KB | Output is correct |
6 | Correct | 11 ms | 1152 KB | Output is correct |
7 | Correct | 256 ms | 22136 KB | Output is correct |
8 | Correct | 0 ms | 256 KB | Output is correct |
9 | Correct | 0 ms | 256 KB | Output is correct |
10 | Correct | 0 ms | 256 KB | Output is correct |
11 | Correct | 0 ms | 256 KB | Output is correct |
12 | Correct | 13 ms | 1152 KB | Output is correct |
13 | Correct | 251 ms | 22136 KB | Output is correct |
14 | Correct | 0 ms | 256 KB | Output is correct |
15 | Correct | 0 ms | 256 KB | Output is correct |
16 | Correct | 6 ms | 640 KB | Output is correct |
17 | Correct | 130 ms | 8268 KB | Output is correct |
18 | Correct | 1 ms | 256 KB | Output is correct |
19 | Correct | 0 ms | 256 KB | Output is correct |
20 | Correct | 64 ms | 5752 KB | Output is correct |
21 | Correct | 257 ms | 22116 KB | Output is correct |
22 | Correct | 253 ms | 22108 KB | Output is correct |
23 | Correct | 274 ms | 22268 KB | Output is correct |
24 | Correct | 249 ms | 22136 KB | Output is correct |
25 | Incorrect | 255 ms | 22264 KB | Answer gives possible 1 while actual possible 0 |
26 | Halted | 0 ms | 0 KB | - |