제출 #432346

#제출 시각아이디문제언어결과실행 시간메모리
432346arayi슈퍼트리 잇기 (IOI20_supertrees)C++17
컴파일 에러
0 ms0 KiB
#include "supertrees.h" #include <bits/stdc++.h> #define ad push_back using namespace std; const int N = 1111; int col[N], sm[N], i1 = 1; vector <vector <int> > b; vector<int> g[N]; int n; void dfs(int v) { col[v] = 2; sm[v]++; for(auto p : g[v]) if(col[i] != 2 && b[v][i]) dfs(i); col[v] = 1; } int construct(std::vector<std::vector<int>> p) { n = p.size(); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) if(p[i][j] > 3) return 0; for (int i = 0; i < n; i++) { if(sm[i]) { for (int j = 0; j < n; j++) { if(p[i][j] && sm[i] != sm[j]) return 0; if(p[i][j] == 0 && sm[i] == sm[j]) return 0; } } else { for (int j = 0; j < n; j++) { if(p[i][j] && sm[j]) return 0; if(p[i][j]) sm[j] = i1; } } i1++; } b.resize(n); for (int i = 0; i < n; i++) b[i].resize(n); for (int i = 1; i < i1; i++) { vector<int> fp; for (int j = 0; j < n; j++) if(sm[j] == i) fp.ad(j); int nx = -1; for (int j = 0; j < fp.size(); j++) { if(col[fp[j]]) continue; if(nx != -1) b[nx][fp[j]] = b[fp[j]][nx] = 1; nx = fp[j]; col[fp[j]] = 1; for (int k = j + 1; k < fp.size(); k++) if(p[fp[j]][fp[k]] == 1) b[fp[j]][fp[k]] = b[fp[k]][fp[j]] = 1, col[fp[k]] = 1; } if(nx != -1 && nx != fp[0]) b[nx][fp[0]] = b[fp[0]][nx] = 1; } for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) if(b[i][j]) g[i].ad(j); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) sm[j] = col[j] = 0; dfs(i); for (int j = 0; j < n; j++) if(sm[j] != p[i][j]) return 0; } build(b); return 1; }

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

supertrees.cpp: In function 'void dfs(int)':
supertrees.cpp:16:10: error: 'i' was not declared in this scope
   16 |   if(col[i] != 2 && b[v][i]) dfs(i);
      |          ^
supertrees.cpp:15:11: warning: unused variable 'p' [-Wunused-variable]
   15 |  for(auto p : g[v])
      |           ^
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:52:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |   for (int j = 0; j < fp.size(); j++)
      |                   ~~^~~~~~~~~~~
supertrees.cpp:58:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |    for (int k = j + 1; k < fp.size(); k++)
      |                        ~~^~~~~~~~~~~