# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
812495 | 2023-08-07T08:57:53 Z | KemalK | Connecting Supertrees (IOI20_supertrees) | C++17 | 630 ms | 23928 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(); bool sub_task_1 = true; bool sub_task_2 = true; for (int i = 0; i < n; i++){ pr[i] = i; } for (int i = 0; i < n; i++){ for (int j = 0; j < i + 1; j++){ if (i != j and p[i][j]){ unit(i, j); } } } for (int i = 0; i < n; i++){ for (int j = 0; j < n; j++){ if (p[i][j] != 1){ sub_task_1 = false; } if (p[i][j] != 2 and p[i][j] != 3){ sub_task_2 = false; } } } std::vector<std::vector<int>> answer; for (int i = 0; i < n; i++) { std::vector<int> row; row.resize(n); answer.push_back(row); } if (n == 1){ //nothing to change } else if (sub_task_1){ // p[i][j] = 1 for (int i = 0; i < n - 1; i++){ answer[i][i + 1] = 1; answer[i + 1][i] = 1; } } else if(sub_task_2) { // p[i][j] = 1 or p[i][j] = 0 map <int, vector<int>> mp; for (int i = 0; i < n; i++){ int x = get(i); mp[x].push_back(i); } for (auto x: mp){ for (int i = 0; i < x.second.size() - 1; i++){ answer[x.second[i]][x.second[i + 1]] = 1; answer[x.second[i + 1]][x.second[i]] = 1; } } } build(answer); return 1; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 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 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 284 KB | Output is correct |
6 | Correct | 10 ms | 1140 KB | Output is correct |
7 | Correct | 630 ms | 22024 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 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 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 284 KB | Output is correct |
6 | Correct | 10 ms | 1140 KB | Output is correct |
7 | Correct | 630 ms | 22024 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 0 ms | 300 KB | Output is correct |
12 | Correct | 6 ms | 1188 KB | Output is correct |
13 | Correct | 159 ms | 23928 KB | Output is correct |
14 | Incorrect | 1 ms | 212 KB | Answer gives possible 1 while actual possible 0 |
15 | Halted | 0 ms | 0 KB | - |
# | 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 | 1 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 0 |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 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 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 284 KB | Output is correct |
6 | Correct | 10 ms | 1140 KB | Output is correct |
7 | Correct | 630 ms | 22024 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 0 ms | 300 KB | Output is correct |
12 | Correct | 6 ms | 1188 KB | Output is correct |
13 | Correct | 159 ms | 23928 KB | Output is correct |
14 | Incorrect | 1 ms | 212 KB | Answer gives possible 1 while actual possible 0 |
15 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 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 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 284 KB | Output is correct |
6 | Correct | 10 ms | 1140 KB | Output is correct |
7 | Correct | 630 ms | 22024 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 0 ms | 300 KB | Output is correct |
12 | Correct | 6 ms | 1188 KB | Output is correct |
13 | Correct | 159 ms | 23928 KB | Output is correct |
14 | Incorrect | 1 ms | 212 KB | Answer gives possible 1 while actual possible 0 |
15 | Halted | 0 ms | 0 KB | - |