Submission #792733

#TimeUsernameProblemLanguageResultExecution timeMemory
792733mousebeaverConnecting Supertrees (IOI20_supertrees)C++14
0 / 100
177 ms22016 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) { return 0; } if(p[i][j]) { component.push_back(j); used[j] = true; } } for(int j : component) { if(count(p[j].begin(), p[j].end(), 0) != n- (int) component.size()) { return 0; } for(int k : component) { if(p[i][j] == 0) { return 0; } } } //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; } } assert(t.size() == 1); 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; }

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:36:12: warning: unused variable 'k' [-Wunused-variable]
   36 |    for(int k : component)
      |            ^
#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...