Submission #548685

#TimeUsernameProblemLanguageResultExecution timeMemory
548685Clan328Connecting Supertrees (IOI20_supertrees)C++17
0 / 100
1 ms212 KiB
#include "supertrees.h" #include <vector> #include <bits/stdc++.h> using namespace std; vector<int> link, sz; int find(int x) { if (link[x] != x) link[x] = find(link[x]); return link[x]; } void unite(int a, int b) { int x = find(a), y = find(b); sz[y] += sz[x]; link[x] = y; } bool same(int a, int b) { return find(a) == find(b); } int construct(vector<vector<int>> p) { int n = p.size(); vector<vector<int>> answer(n, vector<int>(n)); link = vector<int>(n); sz = vector<int>(n, 1); iota(link.begin(), link.end(), 0); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i == j) continue; if (p[i][j] && !same(i, j)) unite(i, j); } } for (int i = 0; i < n; i++) { int prev = i; for (int j = 0; j < n; j++) { if (i == j) continue; if (find(j) == i && p[prev][j] == 2) { answer[prev][j] = 1; answer[j][prev] = 1; prev = j; } } if (prev != i) { answer[prev][i] = 1; answer[i][prev] = 1; } for (int j = 0; j < n; j++) { if (i == j) continue; if (p[i][j] == 1) { answer[i][j] = 1; answer[j][i] = 1; } } } bool res = true; // for (int i = 0; i < n; i++) { // for (int j = 0; j < n; j++) { // if (i == j) continue; // res &= ((p[i][j] == 2) == same(i, j)); // if (same(i, j)) res &= sz[find(i)] > 2; // } // } if (res) { build(answer); return 1; } else return 0; }
#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...