# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
812686 | 2023-08-07T10:09:22 Z | KemalK | Connecting Supertrees (IOI20_supertrees) | C++17 | 1 ms | 432 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 < branch.size() - 1; 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 | Runtime error | 1 ms | 340 KB | Execution killed with signal 11 |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Runtime error | 1 ms | 340 KB | Execution killed with signal 11 |
3 | 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 | Runtime error | 1 ms | 432 KB | Execution killed with signal 11 |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Runtime error | 1 ms | 340 KB | Execution killed with signal 11 |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Runtime error | 1 ms | 340 KB | Execution killed with signal 11 |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Runtime error | 1 ms | 340 KB | Execution killed with signal 11 |
3 | Halted | 0 ms | 0 KB | - |