제출 #413074

#제출 시각아이디문제언어결과실행 시간메모리
413074losmi247슈퍼트리 잇기 (IOI20_supertrees)C++14
40 / 100
262 ms27972 KiB
#include <bits/stdc++.h> #include "supertrees.h" using namespace std; typedef long long ll; const int N = 1005; int n; int p[N][N]; int linija(){ vector <vector<int>> ans; for(int i = 1; i <= n; i++){ vector <int> fg; for(int j = 1; j <= n; j++){ if(j == i+1 || j == i-1) fg.push_back(1); else fg.push_back(0); } ans.push_back(fg); } build(ans); return 1; } bool visited[N]; int komp[N]; int cnt = 1; vector <int> sad; void dfs(int x){ visited[x] = 1; komp[x] = cnt; sad.push_back(x); for(int j = 1; j <= n; j++){ if(p[x][j] && !visited[j]) dfs(j); } } int drvo(){ vector <vector<int>> ans; for(int i = 0; i < n; i++){ vector <int> sta(n,0); ans.push_back(sta); } for(int i = 1; i <= n; i++){ if(visited[i]) continue; sad.clear(); dfs(i); for(int j = 0; j < sad.size()-1; j++){ ans[sad[j]-1][sad[j+1]-1] = ans[sad[j+1]-1][sad[j]-1] = 1; } cnt++; } for(int i = 1; i <= n; i++){ for(int j = 1; j <= n; j++){ if(komp[i] == komp[j] && !p[i][j]) return 0; } } build(ans); return 1; } int krugovi(){ vector <vector<int>> ans; for(int i = 0; i < n; i++){ vector <int> sta(n,0); ans.push_back(sta); } for(int i = 1; i <= n; i++){ if(visited[i]) continue; sad.clear(); dfs(i); if(sad.size() == 2) return 0; for(int j = 0; j < sad.size()-1; j++){ ans[sad[j]-1][sad[j+1]-1] = ans[sad[j+1]-1][sad[j]-1] = 1; } if(sad.size() > 1) ans[sad.back()-1][sad[0]-1] = ans[sad[0]-1][sad.back()-1] = 1; cnt++; } for(int i = 1; i <= n; i++){ for(int j = 1; j <= n; j++){ if(komp[i] == komp[j] && !p[i][j]) return 0; } } build(ans); return 1; } int construct(vector <vector<int>> nz){ n = nz.size(); for(int i = 1; i <= n; i++){ for(int j = 1; j <= n; j++){ p[i][j] = nz[i-1][j-1]; } } bool prvi = 0; for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) prvi |= (p[i][j] != 1); if(!prvi){ return linija(); } bool drugi = 1; for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) if(p[i][j] >= 2) drugi = 0; if(drugi){ return drvo(); } bool treci = 1; for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) if(i != j && p[i][j] != 0 && p[i][j] != 2) treci = 0; if(treci){ return krugovi(); } }

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

supertrees.cpp: In function 'int drvo()':
supertrees.cpp:51:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |         for(int j = 0; j < sad.size()-1; j++){
      |                        ~~^~~~~~~~~~~~~~
supertrees.cpp: In function 'int krugovi()':
supertrees.cpp:79:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |         for(int j = 0; j < sad.size()-1; j++){
      |                        ~~^~~~~~~~~~~~~~
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:121:1: warning: control reaches end of non-void function [-Wreturn-type]
  121 | }
      | ^
#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...