# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
746088 | 2023-05-21T11:38:28 Z | JakobZorz | Connecting Supertrees (IOI20_supertrees) | C++14 | 216 ms | 26152 KB |
#include "supertrees.h" #include <vector> using namespace std; vector<vector<int>> answer; int group_ids[1000]; vector<int> groups[1000]; vector<vector<int>> p; int num_groups; void connect(int a, int b){ answer[a][b]=1; answer[b][a]=1; } int connect_group(int group_id){ vector<int> group=groups[group_id]; vector<bool> in_cycle(group.size(),false); vector<int> tree_ids(group.size(),-1); vector<int> trees[1000]; int num_trees=0; for(int i=0;i<group.size();i++){ if(tree_ids[i]!=-1) continue; tree_ids[i]=num_trees; trees[num_trees].push_back(i); for(int j=0;j<group.size();j++){ if(i!=j&&p[group[i]][group[j]]==1){ tree_ids[j]=num_trees; trees[num_trees].push_back(j); connect(group[i],group[j]); } } num_trees++; } for(int i=0;i<group.size();i++) for(int j=0;j<group.size();j++){ if(tree_ids[i]==tree_ids[j]&&p[group[i]][group[j]]==2) return 0; if(tree_ids[i]!=tree_ids[j]&&p[group[i]][group[j]]==1) return 0; } for(int i=0;i<num_trees-1;i++) connect(group[trees[i][0]],group[trees[i+1][0]]); if(num_trees!=1) connect(group[trees[0][0]],group[trees[num_trees-1][0]]); return 1; } int construct(vector<vector<int>> p_) { p=p_; int n = p.size(); answer=vector<vector<int>>(n,vector<int>(n,0)); for(vector<int>& i:p) for(int j:i) if(j==3) return 0; for(int i=0;i<n;i++) group_ids[i]=-1; for(int i=0;i<n;i++){ if(group_ids[i]!=-1) continue; group_ids[i]=num_groups; groups[num_groups].push_back(i); for(int j=i+1;j<n;j++){ if(p[i][j]!=0){ group_ids[j]=num_groups; groups[num_groups].push_back(j); } } num_groups++; } for(int i=0;i<n;i++) for(int j=i+1;j<n;j++){ if(group_ids[i]!=group_ids[j]&&p[i][j]!=0) return 0; if(group_ids[i]==group_ids[j]&&p[i][j]==0) return 0; } for(int i=0;i<num_groups;i++) if(connect_group(i)==0) return 0; build(answer); return 1; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 8 ms | 1364 KB | Output is correct |
7 | Correct | 174 ms | 25968 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 8 ms | 1364 KB | Output is correct |
7 | Correct | 174 ms | 25968 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 0 ms | 340 KB | Output is correct |
11 | Correct | 0 ms | 340 KB | Output is correct |
12 | Correct | 8 ms | 1364 KB | Output is correct |
13 | Correct | 191 ms | 26060 KB | Output is correct |
14 | Correct | 0 ms | 212 KB | Output is correct |
15 | Correct | 0 ms | 212 KB | Output is correct |
16 | Correct | 4 ms | 856 KB | Output is correct |
17 | Correct | 91 ms | 16016 KB | Output is correct |
18 | Correct | 0 ms | 212 KB | Output is correct |
19 | Correct | 0 ms | 212 KB | Output is correct |
20 | Correct | 53 ms | 6792 KB | Output is correct |
21 | Correct | 187 ms | 26004 KB | Output is correct |
22 | Correct | 216 ms | 25992 KB | Output is correct |
23 | Correct | 196 ms | 25936 KB | Output is correct |
24 | Correct | 187 ms | 26052 KB | Output is correct |
25 | Correct | 95 ms | 16032 KB | Output is correct |
26 | Correct | 91 ms | 16020 KB | Output is correct |
27 | Correct | 188 ms | 26056 KB | Output is correct |
28 | Correct | 208 ms | 26016 KB | Output is correct |
# | 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 | 0 ms | 212 KB | Output is correct |
4 | Incorrect | 0 ms | 212 KB | Answer gives possible 1 while actual possible 0 |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 47 ms | 6804 KB | Output is correct |
5 | Correct | 212 ms | 25940 KB | Output is correct |
6 | Correct | 200 ms | 26032 KB | Output is correct |
7 | Correct | 210 ms | 26040 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 55 ms | 6808 KB | Output is correct |
10 | Correct | 194 ms | 26012 KB | Output is correct |
11 | Correct | 190 ms | 26084 KB | Output is correct |
12 | Correct | 213 ms | 25948 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Correct | 0 ms | 212 KB | Output is correct |
15 | Correct | 0 ms | 212 KB | Output is correct |
16 | Correct | 49 ms | 6788 KB | Output is correct |
17 | Correct | 188 ms | 26008 KB | Output is correct |
18 | Correct | 192 ms | 26016 KB | Output is correct |
19 | Correct | 199 ms | 26036 KB | Output is correct |
20 | Correct | 195 ms | 26152 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 8 ms | 1364 KB | Output is correct |
7 | Correct | 174 ms | 25968 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 0 ms | 340 KB | Output is correct |
11 | Correct | 0 ms | 340 KB | Output is correct |
12 | Correct | 8 ms | 1364 KB | Output is correct |
13 | Correct | 191 ms | 26060 KB | Output is correct |
14 | Correct | 0 ms | 212 KB | Output is correct |
15 | Correct | 0 ms | 212 KB | Output is correct |
16 | Correct | 4 ms | 856 KB | Output is correct |
17 | Correct | 91 ms | 16016 KB | Output is correct |
18 | Correct | 0 ms | 212 KB | Output is correct |
19 | Correct | 0 ms | 212 KB | Output is correct |
20 | Correct | 53 ms | 6792 KB | Output is correct |
21 | Correct | 187 ms | 26004 KB | Output is correct |
22 | Correct | 216 ms | 25992 KB | Output is correct |
23 | Correct | 196 ms | 25936 KB | Output is correct |
24 | Correct | 187 ms | 26052 KB | Output is correct |
25 | Correct | 95 ms | 16032 KB | Output is correct |
26 | Correct | 91 ms | 16020 KB | Output is correct |
27 | Correct | 188 ms | 26056 KB | Output is correct |
28 | Correct | 208 ms | 26016 KB | Output is correct |
29 | Correct | 0 ms | 212 KB | Output is correct |
30 | Correct | 0 ms | 212 KB | Output is correct |
31 | Correct | 0 ms | 212 KB | Output is correct |
32 | Incorrect | 0 ms | 212 KB | Answer gives possible 1 while actual possible 0 |
33 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 8 ms | 1364 KB | Output is correct |
7 | Correct | 174 ms | 25968 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 0 ms | 340 KB | Output is correct |
11 | Correct | 0 ms | 340 KB | Output is correct |
12 | Correct | 8 ms | 1364 KB | Output is correct |
13 | Correct | 191 ms | 26060 KB | Output is correct |
14 | Correct | 0 ms | 212 KB | Output is correct |
15 | Correct | 0 ms | 212 KB | Output is correct |
16 | Correct | 4 ms | 856 KB | Output is correct |
17 | Correct | 91 ms | 16016 KB | Output is correct |
18 | Correct | 0 ms | 212 KB | Output is correct |
19 | Correct | 0 ms | 212 KB | Output is correct |
20 | Correct | 53 ms | 6792 KB | Output is correct |
21 | Correct | 187 ms | 26004 KB | Output is correct |
22 | Correct | 216 ms | 25992 KB | Output is correct |
23 | Correct | 196 ms | 25936 KB | Output is correct |
24 | Correct | 187 ms | 26052 KB | Output is correct |
25 | Correct | 95 ms | 16032 KB | Output is correct |
26 | Correct | 91 ms | 16020 KB | Output is correct |
27 | Correct | 188 ms | 26056 KB | Output is correct |
28 | Correct | 208 ms | 26016 KB | Output is correct |
29 | Correct | 0 ms | 212 KB | Output is correct |
30 | Correct | 0 ms | 212 KB | Output is correct |
31 | Correct | 0 ms | 212 KB | Output is correct |
32 | Incorrect | 0 ms | 212 KB | Answer gives possible 1 while actual possible 0 |
33 | Halted | 0 ms | 0 KB | - |