Submission #1022202

#TimeUsernameProblemLanguageResultExecution timeMemory
1022202hmm789Connecting Supertrees (IOI20_supertrees)C++14
Compilation error
0 ms0 KiB
#include "supertrees.h" #include <bits/stdc++.h> using namespace std; vector<int> grp[1000]; vector<vector<int>> p; int cnt = 0; int pos[1000]; bool v[1000]; void dfs(int x) { grp[cnt].push_back(x); pos[x] = cnt; v[x] = 1; for(int i = 0; i < n; i++) if(!v[i] && p[x][i] == 1) dfs(i); } int construct(std::vector<std::vector<int>> P) { int n = (int)P.size(); vector<vector<int>> ans; for(int i = 0; i < n; i++) { vector<int> v; for(int j = 0; j < n; j++) v.push_back(P[i][j]); p.push_back(v); vector<int> v2; v2.resize(n); ans.push_back(v2); } for(int i = 0; i < n; i++) if(!v[i]) { dfs(i); cnt++; } for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { if(pos[i] != pos[j] && p[i][j] == 1) return 0; if(pos[i] == pos[j] && p[i][j] != 1) return 0; if(p[grp[pos[i]][0]][grp[pos[j]][0]] != p[i][j]) return 0; if(p[i][j] == 3) return 0; } } for(int i = 0; i < cnt; i++) { for(int j = 1; j < grp[i].size(); j++) { ans[grp[i][0]][grp[i][j]] = ans[grp[i][j]][grp[i][0]] = 1; } } memset(v, 0, sizeof(v)); for(int i = 0; i < cnt; i++) if(!v[i]) { v[i] = 1; int prv = i; for(int j = 0; j < cnt; j++) if(!v[j] && p[grp[i][0]][grp[j][0]] == 2) { ans[grp[prv][0]][grp[j][0]] = ans[grp[j][0]][grp[prv][0]] = 1; v[j] = 1; prv = j; } if(prv == i) return 0; ans[grp[prv][0]][grp[i][0]] = ans[grp[i][0]][grp[prv][0]] = 1; } build(ans); return 1; }

Compilation message (stderr)

supertrees.cpp: In function 'void dfs(int)':
supertrees.cpp:15:24: error: 'n' was not declared in this scope
   15 |     for(int i = 0; i < n; i++) if(!v[i] && p[x][i] == 1) dfs(i);
      |                        ^
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:41:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |         for(int j = 1; j < grp[i].size(); j++) {
      |                        ~~^~~~~~~~~~~~~~~