Submission #372987

#TimeUsernameProblemLanguageResultExecution timeMemory
372987Matteo_VerzConnecting Supertrees (IOI20_supertrees)C++17
Compilation error
0 ms0 KiB
#include "supertrees.h" #include <bits/stdc++.h> using namespace std; int construct(vector<vector<int>> p) { int n = p.size(); vector<vector<int>> answer; answer.resize(n); for(int i = 0; i < n; i++) answer[i].resize(n); vector <int> comp; // last subtask, p[i][j] == 3 for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) if(p[i][j] > 2) return 0; if(p[i][i] == 2 || p[i][i] == 0) return 0; } vector <bool> isroot; int countcomp(0); comp.resize(n); isroot.resize(n); for(int i = 0; i < n; i++) { // we consider i to be the root of the connected component if(comp[i] != 0) continue; // it can't be a root comp[i] = ++countcomp; isroot[i] = true; for(int j = 0; j < n; j++) { if(i == j) continue; if(p[i][j] == 1) { // if there is only 1 edge from i to j comp[j] = countcomp; answer[i][j] = answer[j][i] = 1; } } } // now we connect the roots between them to form a cycle // we connect the i-th root with the i+1-th root for(int i = 0; i < n; i++) { if(isroot[i] == true) { for(int j = i + 1; j < n; j++) { if(p[i][j] == 2 && isroot[j]) { answer[i][j] = answer[j][i] = 1; j = n; } } } } // we connect the last with the first root for(int i = 0; i < n; i++) { if(isroot[i] == true) { for(int j = n - 1; j > i; j--) { if(p[i][j] == 2 && isroot[j]) { answer[i][j] = answer[j][i] = 1; j = 0; } } i = n; } } // now we need to verify if our build is fine // 1. We can't have a cycle of length 2 if(countcomp == 2) { for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) if(p[i][j] == 2) return 0; } for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) if(comp[i] != comp[j] && p[i][j] == 1) return 0; else if(comp[i] == comp[j] && (p[i][j] == 0 || p[i][j] == 2) return 0; } build(answer); return 1; }

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:80:67: error: expected ';' before 'return'
   80 |       else if(comp[i] == comp[j] && (p[i][j] == 0 || p[i][j] == 2)
      |                                                                   ^
      |                                                                   ;
   81 |         return 0;
      |         ~~~~~~                                                     
supertrees.cpp:82:3: error: expected primary-expression before '}' token
   82 |   }
      |   ^
supertrees.cpp:81:18: error: expected ')' before '}' token
   81 |         return 0;
      |                  ^
      |                  )
   82 |   }
      |   ~               
supertrees.cpp:80:14: note: to match this '('
   80 |       else if(comp[i] == comp[j] && (p[i][j] == 0 || p[i][j] == 2)
      |              ^
supertrees.cpp:82:3: error: expected primary-expression before '}' token
   82 |   }
      |   ^