Submission #880434

#TimeUsernameProblemLanguageResultExecution timeMemory
880434AkibAzmainConnecting Supertrees (IOI20_supertrees)C++17
0 / 100
1 ms348 KiB
#include <bits/stdc++.h> using namespace std; #include "supertrees.h" #include <vector> int construct(std::vector<std::vector<int>> p) { int n = p.size(); std::vector<std::vector<int>> ans (n, vector < int > (n)); vector < pair < int, int > > dsu (n); map < int, set < int > > s; for (int i = 0; i < n; ++i) dsu[i].first = -1, dsu[i].second = 1; for (int i = 0; i < n; ++i) for (int j = i + 1; j < n; ++j) if (p[i][j] == 2) { int ci = i, cj = j; while (dsu[ci].first != -1) ci = dsu[ci].first; while (dsu[cj].first != -1) cj = dsu[cj].first; if (ci != cj) { if (dsu[ci].second < dsu[cj].second) swap (ci, cj); dsu[cj].first = ci; dsu[ci].second += dsu[cj].second; s[ci].insert (i); s[ci].insert (j); } } for (int i = 0; i < n; ++i) for (int j = i + 1; j < n; ++j) if (p[i][j] == 0) { int ci = i, cj = j; while (dsu[ci].first != -1) ci = dsu[ci].first; while (dsu[cj].first != -1) cj = dsu[cj].first; if (ci == cj) return 0; } for (auto &[y, ss] : s) { int f = *ss.begin (); int p = 0; for (auto &x : ss) if (x != f) ans[x][p] = ans[p][x] = 1, p = x; ans[p][f] = ans[f][p] = 1; } build (ans); 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...