Submission #792716

#TimeUsernameProblemLanguageResultExecution timeMemory
792716mousebeaverConnecting Supertrees (IOI20_supertrees)C++14
11 / 100
168 ms23324 KiB
#include "supertrees.h" #include <bits/stdc++.h> using namespace std; int construct(vector<vector<int>> p) { int n = p.size(); vector<bool> used(n, false); vector<vector<int>> adjmatrix(n, vector<int> (n, 0)); for(int i = 0; i < n; i++) { if(used[i]) continue; //Collect the component: vector<int> component(0); for(int j = 0; j < n; j++) { if(p[i][j] == 3 || used[j]) { return 0; } if(p[i][j]) { component.push_back(j); used[j] = true; } } //Build the forest: vector<bool> tree(component.size(), false); vector<vector<int>> forest(0); for(int j = 0; j < (int) component.size(); j++) { if(tree[j]) continue; vector<int> t(0); for(int k = 0; k < (int) component.size(); k++) { if(p[j][k] == 1) { t.push_back(k); tree[k] = true; } } forest.push_back(t); //Build the tree: for(int k = 0; k < (int) t.size()-1; k++) { adjmatrix[t[k]][t[k+1]] = 1; adjmatrix[t[k+1]][t[k]] = 1; } } //Test the partitioning: for(int j = 0; j < (int) forest.size(); j++) { for(int a : forest[j]) { for(int k = 0; k < (int) forest.size(); k++) { for(int b : forest[k]) { if((k == j && p[a][b] != 1) || (k != j && p[a][b] != 2)) { return 0; } } } } } //Connect the trees: if(forest.size() == 2) { return 0; } if(forest.size() > 2) { for(int j = 0; j < (int) forest.size()-1; j++) { adjmatrix[forest[j][0]][forest[j+1][0]] = 1; adjmatrix[forest[j+1][0]][forest[j][0]] = 1; } adjmatrix[forest[0][0]][forest[forest.size()-1][0]] = 1; adjmatrix[forest[forest.size()-1][0]][forest[0][0]] = 1; } } build(adjmatrix); 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...