제출 #487765

#제출 시각아이디문제언어결과실행 시간메모리
487765ala2슈퍼트리 잇기 (IOI20_supertrees)C++14
40 / 100
198 ms24324 KiB
#include "supertrees.h" #include <vector> #include<iostream> using namespace std; int pa[1001000]; int sz[1001000]; int root(int x) { while(x!=pa[x]) { pa[x]=pa[pa[x]]; x=pa[x]; } return x; } void unit(int x,int y) { x=root(x); y=root(y); if(x==y) return ; if(sz[x]>sz[y]) { sz[x]+=sz[y]; pa[y]=x; } else { sz[y]+=sz[x]; pa[x]=y; } } vector<int>v[10100]; int construct(vector<vector<int>> p) { int n = p.size(); vector<vector<int>> answer; for (int i = 0; i < n; i++) { vector<int> row; row.resize(n); answer.push_back(row); } for(int i=0;i<n;i++) { pa[i]=i; sz[i]=1; } int bb=0; int mm=0; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(p[i][j]==2) mm=1; } } if(mm){ for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(p[i][j]) { //cout<<" "<<i<<" " <<j<<" "<<root(i)<<" "<<root(j)<<" "; unit(i,j); // cout<<root(i)<<endl; } } } for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(p[i][j]&&root(i)!=root(j)) bb=1; if(p[i][j]==0&&root(i)==root(j)) bb=1; } } for(int i=0;i<n;i++) { // cout<<" "<<i<<" "<<root(i)<<endl; v[root(i)].push_back(i); } for(int i=0;i<n;i++) { answer[i][i]=0; if(i!=root(i)) continue; // cout<<v[i].size()<<endl; if(v[i].size()==2) bb=1; for(int j=0;j<v[i].size()-1;j++) { int x=v[i][j]; int y=v[i][j+1]; // cout<<x<<" "; // if(j==v[i].size()-1) // cout<<y<<" "; answer[x][y]=1; answer[y][x]=1; } int y=v[i].size()-1; if(y){ answer[v[i][y]][v[i][0]]=1; answer[v[i][0]][v[i][y]]=1; } } if(bb) return 0; build(answer); return 1; } else { for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(p[i][j]==1) { //cout<<" "<<i<<" " <<j<<" "<<root(i)<<" "<<root(j)<<" "; unit(i,j); // cout<<root(i)<<endl; } } } for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(p[i][j]==1&&root(i)!=root(j)) bb=1; if(p[i][j]==0&&root(i)==root(j)) bb=1; } } for(int i=0;i<n;i++) { // cout<<" "<<i<<" "<<root(i)<<endl; v[root(i)].push_back(i); } for(int i=0;i<n;i++) { if(i!=root(i)) continue; // cout<<v[i].size()<<endl; for(int j=0;j<v[i].size()-1;j++) { int x=v[i][j]; int y=v[i][j+1]; // cout<<x<<" "; // if(j==v[i].size()-1) // cout<<y<<" "; answer[x][y]=1; answer[y][x]=1; } cout<<endl; } if(bb) return 0; build(answer); return 1; } }

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

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:92:7: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   92 |       if(v[i].size()==2)
      |       ^~
supertrees.cpp:94:9: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   94 |         for(int j=0;j<v[i].size()-1;j++)
      |         ^~~
supertrees.cpp:94:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |         for(int j=0;j<v[i].size()-1;j++)
      |                     ~^~~~~~~~~~~~~~
supertrees.cpp:113:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
  113 |     if(bb)
      |     ^~
supertrees.cpp:115:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
  115 |  build(answer);
      |  ^~~~~
supertrees.cpp:154:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  154 |         for(int j=0;j<v[i].size()-1;j++)
      |                     ~^~~~~~~~~~~~~~
supertrees.cpp:167:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
  167 |     if(bb)
      |     ^~
supertrees.cpp:169:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
  169 |  build(answer);
      |  ^~~~~
#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...