제출 #1078814

#제출 시각아이디문제언어결과실행 시간메모리
1078814Faisal_Saqib슈퍼트리 잇기 (IOI20_supertrees)C++17
11 / 100
142 ms31316 KiB
#include "supertrees.h" #include <bits/stdc++.h> using namespace std; const int N=1e3; int reach[N][N],tree_case[N][N]; int par[N],par1[N]; void init(int n) { for(int i=0;i<n;i++) par[i]=par1[i]=i; } int get(int x) { if(par[x]==x)return x; return par[x]=get(par[x]); } int get1(int x) { if(par1[x]==x)return x; return par1[x]=get1(par1[x]); } bool merge(int x,int y) { x=get(x); y=get(y); if(x==y)return 0; par[y]=x; return 1; } bool merge1(int x,int y) { x=get1(x); y=get1(y); if(x==y)return 0; par1[y]=x; return 1; } vector<int> ma[N]; int head; void dfs(int x) { reach[head][x]=1; for(auto y:ma[x]) if(!reach[head][y]) dfs(y); } int construct(std::vector<std::vector<int>> p) { int n = p.size(); init(n); for(int i=0;i<n;i++) { if(p[i][i]!=1) // i i is always one return 0; for(int j=0;j<n;j++) tree_case[i][j]=reach[i][j]=0; } for(int i=0;i<n;i++) { for(int j=i+1;j<n;j++) { if(p[i][j]==1) { tree_case[i][j]=tree_case[j][i]=merge1(i,j); } } } for(int i=0;i<n;i++) { if(i==get(i)) { vector<int> cur={i}; for(int j=i+1;j<n;j++) { if(get(j)==j) { bool han=1; for(auto k:cur) { if(p[k][j]!=2) { han=0; break; } } if(han) { cur.push_back(j); merge(i,j); } } } if(cur.size()==1)continue; if(cur.size()==2) return 0; cur.push_back(i); for(int j=1;j<cur.size();j++) { int x=cur[j-1]; int y=cur[j]; tree_case[x][y]=tree_case[y][x]=1; merge(x,y); } } } for(int i=0;i<n;i++) { for(int j=i+1;j<n;j++) { if(tree_case[i][j]) { ma[i].push_back(j); ma[j].push_back(i); } } } vector<vector<int>> answer(n,vector<int>(n,0)); for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { answer[i][j]=tree_case[i][j]; reach[i][j]=0; } // head=i; // dfs(i); // for(int j=0;j<n;j++) // { // p[i][j]-=(p[i][j]==2);// make 2 to 1 // if(reach[i][j]!=p[i][j]) // { // return 0; // } // } } build(answer); return 1; }

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

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:96:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   96 |    for(int j=1;j<cur.size();j++)
      |                ~^~~~~~~~~~~
#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...