Submission #591813

#TimeUsernameProblemLanguageResultExecution timeMemory
591813penguinhackerConnecting Supertrees (IOI20_supertrees)C++17
0 / 100
1 ms328 KiB
#include "supertrees.h" #include <bits/stdc++.h> using namespace std; const int mxN=1000; int n, who[mxN], cnt; vector<int> adj[mxN], cur_component; vector<vector<int>> p, cmp, ans, edge2; bool vis[mxN]; void dfs0(int i) { who[i]=cnt; for (int j=0; j<n; ++j) if (i!=j&&who[j]==-1&&p[i][j]) dfs0(j); } bool check0() { memset(who, -1, 4*n); cnt=0; for (int i=0; i<n; ++i) if (who[i]==-1) dfs0(i), ++cnt; for (int i=0; i<n; ++i) for (int j=i+1; j<n; ++j) if (who[i]==who[j]&&p[i][j]==0) return 0; return 1; } void dfs1(int i) { who[i]=cnt; for (int j=0; j<n; ++j) if (i!=j&&who[j]==-1&&p[i][j]==1) dfs1(j); } bool check1() { memset(who, -1, 4*n); for (int i=0; i<n; ++i) if (who[i]==-1) cnt=i, dfs1(i); for (int i=0; i<n; ++i) for (int j=i+1; j<n; ++j) if (who[i]==who[j]&&p[i][j]!=1) return 0; for (int j=0; j<cnt; ++j) { int last=-1; for (int i=0; i<n; ++i) if (who[i]==j) { if (last!=-1) ans[last][i]=ans[i][last]=1; last=i; } } return 1; } void dfs2(int i) { vis[i]=1; cur_component.push_back(i); for (int j=0; j<n; ++j) if (who[j]==j&&!vis[j]&&i!=j&&p[i][j]==2) dfs2(j); } bool check2() { memset(vis, 0, n); for (int i=0; i<n; ++i) { if (i!=who[i]||vis[i]) continue; cur_component.clear(); dfs2(i); if (cur_component.size()<=2) return 0; for (int j=0; j<cur_component.size(); ++j) { int a=cur_component[j], b=cur_component[(j+1)%cur_component.size()]; ans[a][b]=ans[b][a]=1; } } return 1; } int construct(vector<vector<int>> _p) { p=_p, n=p.size(); for (int i=0; i<n; ++i) for (int j=i+1; j<n; ++j) if (p[i][j]==3) return 0; ans=edge2=vector<vector<int>>(n, vector<int>(n)); if (!check0()||!check1()||!check2()) return 0; build(ans); return 1; }

Compilation message (stderr)

supertrees.cpp: In function 'bool check2()':
supertrees.cpp:76:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |   for (int j=0; j<cur_component.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...