# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
928030 | 2024-02-15T18:24:35 Z | EJIC_B_KEDAX | Connecting Supertrees (IOI20_supertrees) | C++17 | 1 ms | 348 KB |
#include <bits/stdc++.h> #include "supertrees.h" using ll = long long; using namespace std; const int N = 1010; int dsu[N]; int get(int x) { return dsu[x] == x ? x : dsu[x] = get(dsu[x]); } void merge(int x, int y) { dsu[get(x)] = get(y); } int construct(vector<vector<int>> p) { int n = (int)p.size(); for (int i = 0; i < n; i++) { dsu[i] = i; } for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (p[i][j] == 1) { merge(i, j); } } } vector<vector<int>> b(n, vector<int>(n, 0)), group(n); for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (p[i][j] == 0 && get(i) == get(j)) { return 0; } } group[get(i)].push_back(i); } vector<int> g; for (int i = 0; i < n; i++) { for (int j = 1; j < group[i].size(); j++) { b[group[i][j - 1]][group[i][j]] = 1; b[group[i][j]][group[i][j - 1]] = 1; } if (!group[i].empty()) { g.push_back(i); } group[i].clear(); } for (int i : g) { for (int j : g) { if (p[i][j] == 2 && i < j) { merge(i, j); } } } for (int i : g) { for (int j : g) { if (p[i][j] < 2 && get(i) == get(j) && i < j) { return 0; } } group[get(i)].push_back(i); } for (int i = 0; i < n; i++) { for (int j = 0; j < group[i].size(); j++) { b[group[i][(j - 1 + group[i].size()) % group[i].size()]][group[i][j]] = 1; b[group[i][j]][group[i][(j - 1 + group[i].size()) % group[i].size()]] = 1; } } for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (p[i][j] == 3) { return 0; } } } build(b); return 1; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | b[0][0] is not 0 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | b[0][0] is not 0 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 348 KB | b[0][0] is not 0 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | b[0][0] is not 0 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | b[0][0] is not 0 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | b[0][0] is not 0 |
2 | Halted | 0 ms | 0 KB | - |