# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1114833 | 2024-11-19T16:53:08 Z | presko | Connecting Supertrees (IOI20_supertrees) | C++14 | 155 ms | 24136 KB |
#include "supertrees.h" #include <iostream> #include <vector> #include <algorithm> #define MAXN 1010 using namespace std; int parent[MAXN]; vector<pair<int,int>> used[MAXN]; bool done[MAXN]; int find(int curr) { if(parent[curr]==curr)return curr; return parent[curr]=find(parent[curr]); } void unite(int a, int b, int t) { a=find(a); b=find(b); if(a==b)return; if(used[a].size()<used[b].size())swap(a,b); parent[b]=a; used[a].push_back({t,b}); for(int i=0;i<used[b].size();i++) { if(used[b][i].second==b)continue; used[a].push_back(used[b][i]); } } int construct(vector<vector<int>> p) { int n = p.size(); vector<vector<int>> ans; for(int i=0;i<n;i++) { vector<int> dump(n,0); ans.push_back(dump); parent[i]=i; used[i]={{1,i}}; } for (int i = 0; i < n; i++) { for(int j=0;j<n;j++) { if(i==j)continue; if(p[i][j]==1){unite(i,j,1);} if(p[i][j]==2){unite(i,j,2);} } } for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(p[i][j]==0) { if(find(i)==find(j))return 0; } } } for(int i=0;i<n;i++) { sort(used[i].begin(),used[i].end()); } for(int i=0;i<n;i++) { int x=find(i); if(done[x])continue; for(int j=1;j<used[x].size();j++) { int val=used[x][j].second,t=used[x][j].first; if(t==0 || t==2 || used[x][j-1].first==0)continue; ans[used[x][j-1].second][val]=1; ans[val][used[x][j-1].second]=1; } for(int j=1;j<used[x].size();j++) { int val=used[x][j].second,t=used[x][j].first; if(t==0 || t==1)continue; if(used[x][j-1].first==1) { int left=used[x].size()-j; if(left==1)return 0; if(left==2) { ans[used[x][j-1].second][val]=1; ans[val][used[x][j-1].second]=1; ans[used[x][j-1].second][used[x][j+1].second]=1; ans[used[x][j+1].second][used[x][j-1].second]=1; } else { ans[used[x][j-1].second][val]=1; ans[val][used[x][j-1].second]=1; } continue; } ans[used[x][j-1].second][val]=1; ans[val][used[x][j-1].second]=1; } done[x]=1; } build(ans); return 1; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Correct | 1 ms | 336 KB | Output is correct |
3 | Correct | 1 ms | 336 KB | Output is correct |
4 | Correct | 1 ms | 336 KB | Output is correct |
5 | Correct | 1 ms | 336 KB | Output is correct |
6 | Correct | 6 ms | 1360 KB | Output is correct |
7 | Correct | 138 ms | 22088 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Correct | 1 ms | 336 KB | Output is correct |
3 | Correct | 1 ms | 336 KB | Output is correct |
4 | Correct | 1 ms | 336 KB | Output is correct |
5 | Correct | 1 ms | 336 KB | Output is correct |
6 | Correct | 6 ms | 1360 KB | Output is correct |
7 | Correct | 138 ms | 22088 KB | Output is correct |
8 | Correct | 1 ms | 336 KB | Output is correct |
9 | Correct | 1 ms | 336 KB | Output is correct |
10 | Correct | 1 ms | 336 KB | Output is correct |
11 | Correct | 1 ms | 336 KB | Output is correct |
12 | Correct | 6 ms | 1360 KB | Output is correct |
13 | Correct | 120 ms | 22060 KB | Output is correct |
14 | Correct | 1 ms | 336 KB | Output is correct |
15 | Correct | 1 ms | 336 KB | Output is correct |
16 | Correct | 4 ms | 964 KB | Output is correct |
17 | Correct | 74 ms | 14152 KB | Output is correct |
18 | Correct | 1 ms | 504 KB | Output is correct |
19 | Correct | 1 ms | 336 KB | Output is correct |
20 | Correct | 32 ms | 6224 KB | Output is correct |
21 | Correct | 126 ms | 24136 KB | Output is correct |
22 | Correct | 136 ms | 24136 KB | Output is correct |
23 | Correct | 129 ms | 24136 KB | Output is correct |
24 | Correct | 123 ms | 24136 KB | Output is correct |
25 | Correct | 69 ms | 14116 KB | Output is correct |
26 | Correct | 59 ms | 14248 KB | Output is correct |
27 | Correct | 134 ms | 24100 KB | Output is correct |
28 | Correct | 127 ms | 24136 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Correct | 1 ms | 336 KB | Output is correct |
3 | Correct | 2 ms | 336 KB | Output is correct |
4 | Correct | 1 ms | 336 KB | Output is correct |
5 | Correct | 1 ms | 336 KB | Output is correct |
6 | Correct | 1 ms | 336 KB | Output is correct |
7 | Correct | 1 ms | 336 KB | Output is correct |
8 | Correct | 6 ms | 1360 KB | Output is correct |
9 | Correct | 139 ms | 22088 KB | Output is correct |
10 | Incorrect | 1 ms | 336 KB | Too few ways to get from 0 to 1, should be 2 found 1 |
11 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Correct | 1 ms | 336 KB | Output is correct |
3 | Correct | 1 ms | 336 KB | Output is correct |
4 | Correct | 47 ms | 5708 KB | Output is correct |
5 | Correct | 136 ms | 22088 KB | Output is correct |
6 | Correct | 140 ms | 22204 KB | Output is correct |
7 | Correct | 155 ms | 22200 KB | Output is correct |
8 | Incorrect | 1 ms | 336 KB | Too few ways to get from 0 to 1, should be 2 found 1 |
9 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Correct | 1 ms | 336 KB | Output is correct |
3 | Correct | 1 ms | 336 KB | Output is correct |
4 | Correct | 1 ms | 336 KB | Output is correct |
5 | Correct | 1 ms | 336 KB | Output is correct |
6 | Correct | 6 ms | 1360 KB | Output is correct |
7 | Correct | 138 ms | 22088 KB | Output is correct |
8 | Correct | 1 ms | 336 KB | Output is correct |
9 | Correct | 1 ms | 336 KB | Output is correct |
10 | Correct | 1 ms | 336 KB | Output is correct |
11 | Correct | 1 ms | 336 KB | Output is correct |
12 | Correct | 6 ms | 1360 KB | Output is correct |
13 | Correct | 120 ms | 22060 KB | Output is correct |
14 | Correct | 1 ms | 336 KB | Output is correct |
15 | Correct | 1 ms | 336 KB | Output is correct |
16 | Correct | 4 ms | 964 KB | Output is correct |
17 | Correct | 74 ms | 14152 KB | Output is correct |
18 | Correct | 1 ms | 504 KB | Output is correct |
19 | Correct | 1 ms | 336 KB | Output is correct |
20 | Correct | 32 ms | 6224 KB | Output is correct |
21 | Correct | 126 ms | 24136 KB | Output is correct |
22 | Correct | 136 ms | 24136 KB | Output is correct |
23 | Correct | 129 ms | 24136 KB | Output is correct |
24 | Correct | 123 ms | 24136 KB | Output is correct |
25 | Correct | 69 ms | 14116 KB | Output is correct |
26 | Correct | 59 ms | 14248 KB | Output is correct |
27 | Correct | 134 ms | 24100 KB | Output is correct |
28 | Correct | 127 ms | 24136 KB | Output is correct |
29 | Correct | 1 ms | 336 KB | Output is correct |
30 | Correct | 1 ms | 336 KB | Output is correct |
31 | Correct | 2 ms | 336 KB | Output is correct |
32 | Correct | 1 ms | 336 KB | Output is correct |
33 | Correct | 1 ms | 336 KB | Output is correct |
34 | Correct | 1 ms | 336 KB | Output is correct |
35 | Correct | 1 ms | 336 KB | Output is correct |
36 | Correct | 6 ms | 1360 KB | Output is correct |
37 | Correct | 139 ms | 22088 KB | Output is correct |
38 | Incorrect | 1 ms | 336 KB | Too few ways to get from 0 to 1, should be 2 found 1 |
39 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Correct | 1 ms | 336 KB | Output is correct |
3 | Correct | 1 ms | 336 KB | Output is correct |
4 | Correct | 1 ms | 336 KB | Output is correct |
5 | Correct | 1 ms | 336 KB | Output is correct |
6 | Correct | 6 ms | 1360 KB | Output is correct |
7 | Correct | 138 ms | 22088 KB | Output is correct |
8 | Correct | 1 ms | 336 KB | Output is correct |
9 | Correct | 1 ms | 336 KB | Output is correct |
10 | Correct | 1 ms | 336 KB | Output is correct |
11 | Correct | 1 ms | 336 KB | Output is correct |
12 | Correct | 6 ms | 1360 KB | Output is correct |
13 | Correct | 120 ms | 22060 KB | Output is correct |
14 | Correct | 1 ms | 336 KB | Output is correct |
15 | Correct | 1 ms | 336 KB | Output is correct |
16 | Correct | 4 ms | 964 KB | Output is correct |
17 | Correct | 74 ms | 14152 KB | Output is correct |
18 | Correct | 1 ms | 504 KB | Output is correct |
19 | Correct | 1 ms | 336 KB | Output is correct |
20 | Correct | 32 ms | 6224 KB | Output is correct |
21 | Correct | 126 ms | 24136 KB | Output is correct |
22 | Correct | 136 ms | 24136 KB | Output is correct |
23 | Correct | 129 ms | 24136 KB | Output is correct |
24 | Correct | 123 ms | 24136 KB | Output is correct |
25 | Correct | 69 ms | 14116 KB | Output is correct |
26 | Correct | 59 ms | 14248 KB | Output is correct |
27 | Correct | 134 ms | 24100 KB | Output is correct |
28 | Correct | 127 ms | 24136 KB | Output is correct |
29 | Correct | 1 ms | 336 KB | Output is correct |
30 | Correct | 1 ms | 336 KB | Output is correct |
31 | Correct | 2 ms | 336 KB | Output is correct |
32 | Correct | 1 ms | 336 KB | Output is correct |
33 | Correct | 1 ms | 336 KB | Output is correct |
34 | Correct | 1 ms | 336 KB | Output is correct |
35 | Correct | 1 ms | 336 KB | Output is correct |
36 | Correct | 6 ms | 1360 KB | Output is correct |
37 | Correct | 139 ms | 22088 KB | Output is correct |
38 | Incorrect | 1 ms | 336 KB | Too few ways to get from 0 to 1, should be 2 found 1 |
39 | Halted | 0 ms | 0 KB | - |