제출 #653773

#제출 시각아이디문제언어결과실행 시간메모리
653773coding_snorlaxConnecting Supertrees (IOI20_supertrees)C++14
96 / 100
224 ms23100 KiB
#include "supertrees.h" #include<bits/stdc++.h> using namespace std; int Boss[1005]; int Rank[1005]; int query(int x){ if(Boss[x]==x) return x; else return Boss[x]=query(Boss[x]); } int Union(int x,int y){ int A1=query(x); int A2=query(y); if(A1==A2){ return 0; } if (Rank[A1]>Rank[A2]) Boss[A2]=A1; else if(Rank[A1]<Rank[A2]) Boss[A1]=A2; else{ Boss[A2]=A1; Rank[A1]++; } return 1; } int construct(vector<vector<int>> x){ for(int i=0;i<1005;i++){ Boss[i]=i; Rank[i]=0; } vector<vector<int>> built; for(int i=0;i<x.size();i++){ vector<int> New; for(int j=0;j<x.size();j++){ New.push_back(0); } built.push_back(New); } int check=0; for(int i=0;i<x.size();i++){ for(int j=0;j<x.size();j++){ if (x[i][j]) check=Union(i,j); } } int New_Boss[1005]; for(int i=0;i<1005;i++){ New_Boss[i]=query(i); } //renew Union set; for(int i=0;i<1005;i++){ Boss[i]=i; Rank[i]=0; } vector<int> under_going={0}; for(int i=0;i<(int)x.size();i++){ for(int j=0;j<(int)x.size();j++){ if(x[i][j]==1) Union(i,j); } } int now_Boss=New_Boss[0]; int Mark[1005]={0}; vector<int> tmp_List={0}; vector<int> cycle[1005]; for(int Time=0;Time<(int)x.size();Time++){ if(!Mark[Time]){ now_Boss=query(Time); cycle[New_Boss[Time]].push_back(Time); Mark[Time]=1; for(int i=0;i<(int)x.size();i++){ if(now_Boss==query(i)&&Time!=i&&!Mark[i]){ //must=1 Mark[i]=1; if(query(i)==now_Boss){ built[i][now_Boss]=1; built[now_Boss][i]=1; } } } } } int answer=1; for(int i=0;i<1005;i++){ if((int)cycle[i].size()>2){ for(int j=0;j<(int)cycle[i].size()-1;j++){ built[cycle[i][j]][cycle[i][j+1]]=1; built[cycle[i][j+1]][cycle[i][j]]=1; } built[cycle[i][0]][cycle[i][(int)cycle[i].size()-1]]=1; built[cycle[i][(int)cycle[i].size()-1]][cycle[i][0]]=1; } else{ if((int)cycle[i].size()==2) answer=0; } } for(int i=0;i<(int)x.size();i++){ for(int j=0;j<(int)x.size();j++){ if(x[i][j]==2 && (!New_Boss[i]==New_Boss[j] || query(i)==query(j))) answer=0; if(x[i][j]==1 && (!New_Boss[i]==New_Boss[j] || !query(i)==query(j))) answer=0; if(x[i][j]==0 && (New_Boss[i]==New_Boss[j])) answer=0; } } if(answer) build(built); return answer; }

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

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:30:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     for(int i=0;i<x.size();i++){
      |                 ~^~~~~~~~~
supertrees.cpp:32:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |         for(int j=0;j<x.size();j++){
      |                     ~^~~~~~~~~
supertrees.cpp:38:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |     for(int i=0;i<x.size();i++){
      |                 ~^~~~~~~~~
supertrees.cpp:39:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |         for(int j=0;j<x.size();j++){
      |                     ~^~~~~~~~~
supertrees.cpp:95:43: warning: logical not is only applied to the left hand side of comparison [-Wlogical-not-parentheses]
   95 |             if(x[i][j]==2 && (!New_Boss[i]==New_Boss[j] || query(i)==query(j))) answer=0;
      |                                           ^~
supertrees.cpp:95:31: note: add parentheses around left hand side expression to silence this warning
   95 |             if(x[i][j]==2 && (!New_Boss[i]==New_Boss[j] || query(i)==query(j))) answer=0;
      |                               ^~~~~~~~~~~~
      |                               (           )
supertrees.cpp:96:43: warning: logical not is only applied to the left hand side of comparison [-Wlogical-not-parentheses]
   96 |             if(x[i][j]==1 && (!New_Boss[i]==New_Boss[j] || !query(i)==query(j))) answer=0;
      |                                           ^~
supertrees.cpp:96:31: note: add parentheses around left hand side expression to silence this warning
   96 |             if(x[i][j]==1 && (!New_Boss[i]==New_Boss[j] || !query(i)==query(j))) answer=0;
      |                               ^~~~~~~~~~~~
      |                               (           )
supertrees.cpp:96:69: warning: logical not is only applied to the left hand side of comparison [-Wlogical-not-parentheses]
   96 |             if(x[i][j]==1 && (!New_Boss[i]==New_Boss[j] || !query(i)==query(j))) answer=0;
      |                                                                     ^~
supertrees.cpp:96:60: note: add parentheses around left hand side expression to silence this warning
   96 |             if(x[i][j]==1 && (!New_Boss[i]==New_Boss[j] || !query(i)==query(j))) answer=0;
      |                                                            ^~~~~~~~~
      |                                                            (        )
supertrees.cpp:37:9: warning: variable 'check' set but not used [-Wunused-but-set-variable]
   37 |     int check=0;
      |         ^~~~~
#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...