Submission #591819

#TimeUsernameProblemLanguageResultExecution timeMemory
591819penguinhackerConnecting Supertrees (IOI20_supertrees)C++17
19 / 100
191 ms31944 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() { for (int i=0; i<n; ++i) for (int j=0; j<n; ++j) if (p[i][j]!=1&&p[i][j]!=p[who[i]][who[j]]) return 0; memset(vis, 0, n); for (int i=0; i<n; ++i) { if (i!=who[i]||vis[i]) continue; cur_component.clear(); dfs2(i); //cout << i << endl; if (cur_component.size()==1) continue; 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:83:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |   for (int j=0; j<cur_component.size(); ++j) {
      |                 ~^~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/string.h:495,
                 from /usr/include/c++/10/cstring:42,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:48,
                 from supertrees.cpp:2:
In function 'void* memset(void*, int, size_t)',
    inlined from 'bool check2()' at supertrees.cpp:72:8:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:71:33: warning: 'void* __builtin___memset_chk(void*, int, long unsigned int, long unsigned int)' specified size between 18446744071562067968 and 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=]
   71 |   return __builtin___memset_chk (__dest, __ch, __len, __bos0 (__dest));
      |          ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...