제출 #312425

#제출 시각아이디문제언어결과실행 시간메모리
312425huangqr슈퍼트리 잇기 (IOI20_supertrees)C++14
컴파일 에러
0 ms0 KiB
#include "supertrees.h" #include <bits/stdc++.h> using namespace std; int construct(std::vector<std::vector<int>> p) { int vis[1005]; std::vector<std::vector<int>> answer; int n=p.size(); nnn=n; for(int i=0;i<n;i++){ for(int j=0;j<n;j++)if(p[i][j]==3||p[j][i]!=p[i][j])return 0; } int group[1005],small[1005],ctr=-1,ctr2=-1;; vector<set<int> >groups,smalls; unordered_map<int,vector<int> >groupstosmalls; for(int i=0;i<n;i++)group[i]=small[i]=-1; for(int i=0;i<n;i++){ if(p[i][i]!=1)return 0; vector<int>r=p[i]; if(group[i]==-1){ group[i]=++ctr; set<int>cgp={i}; for(int j=0;j<n;j++){ if(j==i)continue; if(r[j]){ if(group[j]!=-1)return 0; group[j]=ctr; cgp.insert(j); } } groups.push_back(cgp); } else{ int g=group[i]; for(int j=0;j<n;j++){ if(group[j]==g&&r[j]==0)return 0; if(group[j]!=g&&r[j])return 0; } } if(small[i]==-1){ small[i]=i; groupstosmalls[group[i]].push_back(i); set<int>cgp={i}; for(int j=0;j<n;j++){ if(j==i)continue; if(r[j]==1){ if(small[j]!=-1)return 0; small[j]=i; cgp.insert(j); } } smalls.push_back(cgp); } else{ int g=small[i]; for(int j=0;j<n;j++){ if(small[j]==g&&r[j]!=1)return 0; if(small[j]!=g&&r[j]==1)return 0; } } } ctr++; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(group[i]!=group[j]&&p[i][j]!=0)return 0; if(group[i]==group[j]&&p[i][j]==0)return 0; if(small[i]==small[j]&&group[i]!=group[j])return 0; if(small[i]==small[j]&&p[i][j]!=1)return 0; if(small[i]!=small[j]&&group[i]==group[j]&&p[i][j]!=2)return 0; } } //Set up the empty answer for (int i = 0; i < n; i++) { std::vector<int> row; for(int j=0;j<n;j++)row.push_back(0); answer.push_back(row); } //Creating lines from the sub-groups (smalls) for(auto x:smalls){ auto y=++x.begin(),yy=x.begin(); while(y!=x.end()){ answer[*y][*yy]=answer[*yy][*y]=1; y++,yy++; } } for(auto x:groupstosmalls){ //Creating circles using 1 member of each sub-group if(x.second.size()==1)continue; //No links formed if(x.second.size()==2)return 0; //No loop is formed with only 2 members. This a crucial line. for(int i=0;i<x.second.size()-1;i++){ answer[x.second[i]][x.second[i+1]]=answer[x.second[i+1]][x.second[i]]=1; } answer[x.second[0]][x.second[x.second.size()-1]]=answer[x.second[x.second.size()-1]][x.second[0]]=1; } build(answer); return 1; } /* cout<<"Groups\n"; for(auto x:groups){ for(auto y:x){ cout<<y<<" "; } cout<<"\n"; } cout<<"Smalls\n"; for(auto x:smalls){ for(auto y:x){ cout<<y<<" "; } cout<<"\n"; } cout<<"g2s\n"; for(auto x:groupstosmalls){ cout<<x.first<<": "; for(auto y:x.second)cout<<y<<" "; cout<<"\n"; } cout<<"small_val\n"; for(int i=0;i<n;i++)cout<<small[i]<<" "; cout<<"\n";*/

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

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:9:2: error: 'nnn' was not declared in this scope; did you mean 'nan'?
    9 |  nnn=n;
      |  ^~~
      |  nan
supertrees.cpp:94:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |   for(int i=0;i<x.second.size()-1;i++){
      |               ~^~~~~~~~~~~~~~~~~~
supertrees.cpp:6:6: warning: unused variable 'vis' [-Wunused-variable]
    6 |  int vis[1005];
      |      ^~~
supertrees.cpp:13:37: warning: unused variable 'ctr2' [-Wunused-variable]
   13 |  int group[1005],small[1005],ctr=-1,ctr2=-1;;
      |                                     ^~~~