제출 #1119128

#제출 시각아이디문제언어결과실행 시간메모리
1119128alexddConnecting Supertrees (IOI20_supertrees)C++17
컴파일 에러
0 ms0 KiB
#include<bits/stdc++.h> #include "supertrees.h" using namespace std; int n; vector<int> comp; bool visited[1005]; vector<int> comp; void dfs(int nod) { comp.push_back(nod); visited[nod]=1; for(int i=1;i<=n;i++) if(!visited[i] && p[nod][i]>0) dfs(i); } vector<int> aux; void dfs2(int nod) { visited[nod]=1; aux.push_back(nod); for(int i=1;i<=n;i++) if(!visited[i] && p[nod][i]==1) dfs2(i); } int construct(vector<vector<int>> p) { n = p.size(); vector<vector<int>> b(n, vector<int>(n)); for(int i=0;i<n;i++) { if(!visited[i]) { comp.clear(); dfs(i); for(int x:comp) visited[x]=0; vector<int> roots; for(int x:comp) { if(!visited[x]) { roots.push_back(x); aux.clear(); dfs2(x); for(auto y:aux) if(y!=x) b[x][y]=b[y][x]=1; } } if((int)roots.size() == 2) return 0; if((int)roots.size() > 1) { for(int i=0;i+1<roots.size();i++) b[roots[i]][roots[i+1]] = b[roots[i+1]][roots[i]] = 1; b[roots[0]][roots.back()] = b[roots.back()][roots[0]] = 1; } } } build(b); return 1; }

컴파일 시 표준 에러 (stderr) 메시지

supertrees.cpp:7:13: error: redefinition of 'std::vector<int> comp'
    7 | vector<int> comp;
      |             ^~~~
supertrees.cpp:5:13: note: 'std::vector<int> comp' previously declared here
    5 | vector<int> comp;
      |             ^~~~
supertrees.cpp: In function 'void dfs(int)':
supertrees.cpp:13:27: error: 'p' was not declared in this scope
   13 |         if(!visited[i] && p[nod][i]>0)
      |                           ^
supertrees.cpp: In function 'void dfs2(int)':
supertrees.cpp:22:27: error: 'p' was not declared in this scope
   22 |         if(!visited[i] && p[nod][i]==1)
      |                           ^
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:54:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |                 for(int i=0;i+1<roots.size();i++)
      |                             ~~~^~~~~~~~~~~~~