# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
591819 | 2022-07-08T00:42:48 Z | penguinhacker | Connecting Supertrees (IOI20_supertrees) | C++17 | 191 ms | 31944 KB |
#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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Incorrect | 0 ms | 212 KB | Too few ways to get from 0 to 1, should be 1 found 0 |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Incorrect | 0 ms | 212 KB | Too few ways to get from 0 to 1, should be 1 found 0 |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 8 ms | 1600 KB | Output is correct |
9 | Correct | 177 ms | 31896 KB | Output is correct |
10 | Correct | 0 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 328 KB | Output is correct |
12 | Correct | 7 ms | 1620 KB | Output is correct |
13 | Correct | 169 ms | 31904 KB | Output is correct |
14 | Correct | 1 ms | 328 KB | Output is correct |
15 | Correct | 1 ms | 212 KB | Output is correct |
16 | Correct | 4 ms | 1108 KB | Output is correct |
17 | Correct | 77 ms | 22032 KB | Output is correct |
18 | Correct | 0 ms | 212 KB | Output is correct |
19 | Correct | 0 ms | 324 KB | Output is correct |
20 | Correct | 0 ms | 212 KB | Output is correct |
21 | Correct | 43 ms | 8268 KB | Output is correct |
22 | Correct | 183 ms | 31820 KB | Output is correct |
23 | Correct | 169 ms | 31812 KB | Output is correct |
24 | Correct | 188 ms | 31944 KB | Output is correct |
25 | Correct | 74 ms | 21964 KB | Output is correct |
26 | Correct | 70 ms | 21916 KB | Output is correct |
27 | Correct | 172 ms | 31904 KB | Output is correct |
28 | Correct | 191 ms | 31884 KB | Output is correct |
29 | Correct | 78 ms | 21992 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 324 KB | Output is correct |
3 | Incorrect | 1 ms | 212 KB | Too few ways to get from 1 to 2, should be 1 found 0 |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Incorrect | 0 ms | 212 KB | Too few ways to get from 0 to 1, should be 1 found 0 |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Incorrect | 0 ms | 212 KB | Too few ways to get from 0 to 1, should be 1 found 0 |
3 | Halted | 0 ms | 0 KB | - |