Submission #770820

#TimeUsernameProblemLanguageResultExecution timeMemory
770820SanguineChameleonConnecting Supertrees (IOI20_supertrees)C++17
21 / 100
159 ms26700 KiB
#include "supertrees.h" #include <bits/stdc++.h> using namespace std; const int maxn = 1e3 + 20; int cnt[maxn][maxn]; vector<vector<int>> res; bool flag[maxn]; int n; void add_edge(int u, int v) { res[u][v] = true; res[v][u] = true; } bool solve(vector<int> comp) { for (auto u: comp) { for (auto v: comp) { if (cnt[u][v] == 0) { return false; } } } for (int i = 0; i < (int)comp.size() - 1; i++) { add_edge(comp[i], comp[i + 1]); } return true; } int construct(vector<vector<int>> _cnt) { n = _cnt.size(); res.resize(n, vector<int>(n, 0)); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cnt[i][j] = _cnt[i][j]; if (cnt[i][j] == 3) { return 0; } } } for (int i = 0; i < n; i++) { if (!flag[i]) { flag[i] = true; vector<int> comp = {i}; int pt = 0; int sz = 1; while (pt < sz) { int u = comp[pt++]; for (int v = 0; v < n; v++) { if (!flag[v] && cnt[u][v] > 0) { flag[v] = true; comp.push_back(v); sz++; } } } if (!solve(comp)) { return 0; } } } build(res); 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...