# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
303131 | 2020-09-19T22:52:48 Z | qpwoeirut | Connecting Supertrees (IOI20_supertrees) | C++17 | 1 ms | 384 KB |
#include "supertrees.h" #include <bits/stdc++.h> using namespace std; typedef vector<vector<int>> vvi; typedef pair<int,int> pii; const int MN = 1001; int N; 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) { int ru = par(u), rv = par(v); if (ru == rv) return; root[ru] = rv; } 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] == 3) return 0; if (p[i][j]) join(i, j); } } for (int i=0; i<N; ++i) { for (int j=0; j<N; ++j) { if (p[i][j] == 0 && par(i) == par(j)) return 0; } } return 1; } int ones[MN]; vvi ans; bool make_part(const vvi& p, const vector<int>& nodes) { set<pii, greater<pii>> q; for (int i=0; i<nodes.size(); ++i) { q.insert(pii(ones[nodes[i]], nodes[i])); } int root = -1; int last = -1; while (q.size() > 0) { int cur = q.begin()->second; q.erase(q.begin()); if (root == -1) { root = cur; } if (last != -1) { ans[cur][last] = 1; ans[last][cur] = 1; } last = cur; for (int i=0; i<N; ++i) { if (p[cur][i] == 1) { if (ones[i] != 1) { return false; } ans[cur][i] = 1; ans[i][cur] = 1; q.erase(pii(ones[i], i)); } } } return 1; } int construct(std::vector<std::vector<int>> p) { N = p.size(); if (!dsu(p)) return 0; map<int, vector<int>> parts; for (int i=0; i<N; ++i) { parts[par(i)].push_back(i); for (int j=0; j<N; ++j) { if (p[i][j] == 1) ++ones[i]; } } ans = vvi(N, vector<int>(N)); for (auto it=parts.begin(); it!=parts.end(); ++it) { if (!make_part(p, it->second)) return 0; } build(ans); return 1; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 384 KB | b[0][0] is not 0 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 384 KB | b[0][0] is not 0 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 256 KB | b[0][0] is not 0 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 256 KB | b[0][0] is not 0 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 384 KB | b[0][0] is not 0 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 384 KB | b[0][0] is not 0 |
2 | Halted | 0 ms | 0 KB | - |