Submission #300389

#TimeUsernameProblemLanguageResultExecution timeMemory
300389kshitij_sodaniConnecting Supertrees (IOI20_supertrees)C++14
100 / 100
282 ms26252 KiB
#include <bits/stdc++.h> using namespace std; #define a first #define b second #define pb push_back typedef long long llo; #include "supertrees.h" #include <vector> vector<vector<int>> adj; int vis[1001]; vector<int> comp; int n; void dfs(int no){ comp.pb(no); vis[no]=1; for(int i=0;i<n;i++){ if(adj[no][i]==1 and vis[i]==0){ dfs(i); } } } int par[1001]; void dfs2(int no){ comp.pb(no); vis[no]=1; for(int i=0;i<n;i++){ if(adj[no][par[i]]==2 and vis[par[i]]==0){ dfs2(par[i]); } } } int par2[1001]; void dfs3(int no){ comp.pb(no); vis[no]=1; for(int i=0;i<n;i++){ if(adj[no][par2[i]]==3 and vis[par2[i]]==0){ dfs3(par2[i]); } } } vector<int> comp2[1001]; vector<int> comp3[1001]; int construct(vector<vector<int>> p) { n = p.size(); adj=p; vector<vector<int>> ans; for(int i=0;i<n;i++){ vector<int> pp; for(int j=0;j<n;j++){ pp.pb(0); } ans.pb(pp); } for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(adj[i][j]==3){ return 0; } } } for(int i=0;i<n;i++){ if(vis[i]==0){ comp.clear(); dfs(i); for(auto j:comp){ for(auto k:comp){ if(j!=k){ if(adj[j][k]!=1){ return 0; } } } } for(auto j:comp){ par[j]=comp[0]; } comp2[comp[0]]=comp; for(int j=0;j<comp.size()-1;j++){ ans[comp[j]][comp[j+1]]=1; ans[comp[j+1]][comp[j]]=1; } } } for(int i=0;i<n;i++){ vis[i]=0; } for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(i==j){ continue; } if(par[i]!=i or par[j]!=j){ continue; } int x=adj[i][j]; for(auto jj:comp2[i]){ for(auto kk:comp2[j]){ if(adj[jj][kk]!=x){ return 0; } } } /*if(adj[i][j]!=adj[par[i]][par[j]]){ // cout<<i<<":"<<j<<endl; return 0; }*/ } } for(int i=0;i<n;i++){ if(vis[par[i]]==0){ comp.clear(); dfs2(par[i]); for(auto j:comp){ for(auto jj:comp2[j]){ par2[jj]=comp[0]; comp3[comp[0]].pb(jj); } } if(comp.size()==2){ return 0; } for(auto j:comp){ for(auto k:comp){ if(j!=k){ if(adj[j][k]!=2){ return 0; } } } } for(int j=0;j<comp.size()-1;j++){ ans[comp[j]][comp[j+1]]=1; ans[comp[j+1]][comp[j]]=1; } if(comp.size()>1){ ans[comp[0]][comp.back()]=1; ans[comp.back()][comp[0]]=1; } } } for(int i=0;i<n;i++){ vis[i]=0; } for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(i==j){ continue; } if(par2[i]!=i or par2[j]!=j){ continue; } int x=adj[i][j]; for(auto jj:comp3[i]){ for(auto kk:comp3[j]){ if(adj[jj][kk]!=x){ return 0; } } } /*if(adj[i][j]!=adj[par[i]][par[j]]){ // cout<<i<<":"<<j<<endl; return 0; }*/ } } for(int i=0;i<n;i++){ if(vis[par2[i]]==0){ comp.clear(); dfs3(par[i]); if(comp.size()==2 or comp.size()==3){ return 0; } for(auto j:comp){ for(auto k:comp){ if(j!=k){ if(adj[j][k]!=3){ return 0; } } } } for(int j=0;j<comp.size()-1;j++){ ans[comp[j]][comp[j+1]]=1; ans[comp[j+1]][comp[j]]=1; } if(comp.size()>1){ ans[comp[0]][comp.back()]=1; ans[comp.back()][comp[0]]=1; ans[comp[0]][comp[2]]=1; ans[comp[2]][comp[0]]=1; } } } build(ans); return 1; }

Compilation message (stderr)

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