Submission #1002293

#TimeUsernameProblemLanguageResultExecution timeMemory
1002293toast12Connecting Supertrees (IOI20_supertrees)C++14
0 / 100
0 ms348 KiB
#include "supertrees.h" #include <vector> #include <map> #include <iostream> using namespace std; struct DSU { int n; vector<int> link, size; DSU(int sz) { n = sz; link.resize(sz); size.resize(sz); for (int i = 0; i < n; i++) { link[i] = i; size[i] = 1; } } int find(int x) { while (x != link[x]) x = link[x]; return x; } bool same(int a, int b) { return find(a) == find(b); } void unite(int a, int b) { a = find(a); b = find(b); if (a == b) return; if (size[a] < size[b]) swap(a, b); link[b] = a; size[a] += size[b]; } }; int construct(std::vector<vector<int>> p) { int n = p.size(); vector<vector<int>> answer(n, vector<int>(n)); vector<vector<int>> c(n); DSU d(n+1); for (int i = 0; i < n; i++) { c[i].push_back(i); for (int j = 0; j < n; j++) { if (i == j) continue; if (p[i][j]) { if (!d.same(i, j)) { d.unite(i, j); c[d.find(i)].push_back(j); } } } } for (int i = 0; i < n; i++) { if (c[i].size() == 1) continue; if (c[i].size() == 2) return 0; for (int j = 0; j < (int)c[i].size(); j++) { for (int k = j+1; k < (int)c[i].size(); k++) { if (!p[c[i][j]][c[i][k]]) return 0; } } for (int j = 0; j < (int)c[i].size()-2; j++) { answer[c[i][j]][c[i][j+1]] = 1; answer[c[i][j+1]][c[i][j]] = 1; } answer[c[i][0]][c[i].back()] = 1; answer[c[i].back()][c[i][0]] = 1; } build(answer); return 1; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...