Submission #728112

#TimeUsernameProblemLanguageResultExecution timeMemory
728112hoainiemConnecting Supertrees (IOI20_supertrees)C++14
21 / 100
184 ms24144 KiB
#include "supertrees.h" #include <bits/stdc++.h> using namespace std; int n, flag[1008]; bool kt[1008]; vector<int>ds, cir, tour, vt[1008]; vector<vector<int> >a; int construct(std::vector<std::vector<int>> p) { n = p.size(); a.resize(n); for (int i = 0; i < n; i++){ for (int j = i + 1; j < n; j++) assert(p[i][j] < 3); a[i].resize(n, 0); } fill(kt, kt + n, false); for (int i = 0; i < n; i++) if (!kt[i]){ ds.push_back(i); vt[i].push_back(i); kt[i] = true; flag[i] = i; for (int j = i + 1; j < n; j++) if (!kt[j] && p[i][j] == 1){ vt[i].push_back(j); kt[j] = true; flag[j] = i; } for (int u : vt[i]) for (int v : vt[i]) if (p[u][v] != 1) return 0; for (int pos = 1; pos < (int)vt[i].size(); pos++) a[vt[i][pos]][vt[i][pos - 1]] = a[vt[i][pos - 1]][vt[i][pos]] = 1; } for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) if (p[i][j] == 1 && flag[i] != flag[j]) return 0; fill(kt, kt + n, false); for (int i : ds) if (!kt[i]){ cir.clear(); tour.clear(); kt[i] = true; tour.push_back(i); for (int j : ds) if (p[i][j] == 2){ if (kt[j]) return 0; tour.push_back(j); kt[j] = true; for (int u : vt[j]) for (int v : cir) if (p[u][v] != 2) return 0; for (int u : vt[j]) cir.push_back(u); } if (tour.size() <= 2){ if (tour.size() == 2) return 0; else break; } tour.push_back(tour[0]); for (int pos = 1; pos < (int)tour.size(); pos++) a[tour[pos]][tour[pos - 1]] = a[tour[pos - 1]][tour[pos]] = 1; } build(a); 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...