# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1078775 | 2024-08-28T06:05:17 Z | Faisal_Saqib | 슈퍼트리 잇기 (IOI20_supertrees) | C++17 | 172 ms | 31316 KB |
#include "supertrees.h" #include <bits/stdc++.h> using namespace std; const int N=1e3; int reach[N][N],tree_case[N][N]; int par[N]; void init(int n) { for(int i=0;i<n;i++) par[i]=i; } int get(int x) { if(par[x]==x)return x; return par[x]=get(par[x]); } bool merge(int x,int y) { x=get(x); y=get(y); if(x==y)return 0; par[y]=x; return 1; } vector<int> ma[N]; int head; void dfs(int x) { reach[head][x]=1; for(auto y:ma[x]) if(!reach[head][y]) dfs(y); } int construct(std::vector<std::vector<int>> p) { int n = p.size(); init(n); bool two=0; for(int i=0;i<n;i++) { if(p[i][i]!=1) return 0; for(int j=0;j<n;j++) { two|=(p[i][j]==2); tree_case[i][j]=reach[i][j]=0; } } if(two) { for(int i=0;i<n;i++) { for(int j=i+1;j<n;j++) { if(p[i][j]==2) { merge(i,j); } } } for(int i=0;i<n;i++) { if(get(i)==i) { vector<int> component; for(int j=0;j<n;j++) { if(get(j)==i) { component.push_back(j); } } if(component.size()==1)continue; if(component.size()==2) return 0; component.push_back(component[0]); for(int i=1;i<component.size();i++) { tree_case[component[i-1]][component[i]]=1; tree_case[component[i]][component[i-1]]=1; } } } } else { for(int i=0;i<n;i++) { for(int j=i+1;j<n;j++) { if(p[i][j]==1) { tree_case[i][j]=tree_case[j][i]=merge(i,j); } } } } for(int i=0;i<n;i++) { for(int j=i+1;j<n;j++) { if(tree_case[i][j]) { ma[i].push_back(j); ma[j].push_back(i); } } } vector<vector<int>> answer(n,vector<int>(n,0)); for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { answer[i][j]=tree_case[i][j]; reach[i][j]=0; } head=i; dfs(i); for(int j=0;j<n;j++) { p[i][j]-=(p[i][j]==2);// make 2 to 1 if(reach[i][j]!=p[i][j]) { return 0; } } } build(answer); return 1; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 392 KB | Output is correct |
5 | Correct | 1 ms | 348 KB | Output is correct |
6 | Correct | 11 ms | 2908 KB | Output is correct |
7 | Correct | 172 ms | 30036 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 392 KB | Output is correct |
5 | Correct | 1 ms | 348 KB | Output is correct |
6 | Correct | 11 ms | 2908 KB | Output is correct |
7 | Correct | 172 ms | 30036 KB | Output is correct |
8 | Correct | 1 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Correct | 1 ms | 348 KB | Output is correct |
11 | Correct | 0 ms | 348 KB | Output is correct |
12 | Correct | 5 ms | 2908 KB | Output is correct |
13 | Correct | 139 ms | 29992 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 0 ms | 348 KB | Output is correct |
16 | Correct | 3 ms | 2396 KB | Output is correct |
17 | Correct | 87 ms | 20020 KB | Output is correct |
18 | Correct | 0 ms | 348 KB | Output is correct |
19 | Correct | 0 ms | 344 KB | Output is correct |
20 | Correct | 32 ms | 9868 KB | Output is correct |
21 | Correct | 123 ms | 30036 KB | Output is correct |
22 | Correct | 121 ms | 30036 KB | Output is correct |
23 | Correct | 156 ms | 29988 KB | Output is correct |
24 | Correct | 121 ms | 30008 KB | Output is correct |
25 | Correct | 62 ms | 20056 KB | Output is correct |
26 | Correct | 54 ms | 20052 KB | Output is correct |
27 | Correct | 154 ms | 30040 KB | Output is correct |
28 | Correct | 135 ms | 30016 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 1 ms | 348 KB | Output is correct |
7 | Correct | 1 ms | 348 KB | Output is correct |
8 | Correct | 6 ms | 2908 KB | Output is correct |
9 | Correct | 125 ms | 30008 KB | Output is correct |
10 | Correct | 1 ms | 344 KB | Output is correct |
11 | Correct | 1 ms | 348 KB | Output is correct |
12 | Correct | 6 ms | 2908 KB | Output is correct |
13 | Correct | 136 ms | 29888 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 1 ms | 348 KB | Output is correct |
16 | Correct | 3 ms | 2396 KB | Output is correct |
17 | Correct | 64 ms | 20048 KB | Output is correct |
18 | Correct | 0 ms | 348 KB | Output is correct |
19 | Correct | 1 ms | 348 KB | Output is correct |
20 | Correct | 0 ms | 348 KB | Output is correct |
21 | Correct | 36 ms | 10204 KB | Output is correct |
22 | Correct | 131 ms | 31228 KB | Output is correct |
23 | Correct | 126 ms | 31316 KB | Output is correct |
24 | Correct | 158 ms | 31220 KB | Output is correct |
25 | Correct | 59 ms | 17312 KB | Output is correct |
26 | Correct | 61 ms | 21328 KB | Output is correct |
27 | Correct | 122 ms | 31236 KB | Output is correct |
28 | Correct | 132 ms | 31284 KB | Output is correct |
29 | Correct | 57 ms | 17232 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 32 ms | 9696 KB | Output is correct |
5 | Correct | 119 ms | 30000 KB | Output is correct |
6 | Correct | 120 ms | 30032 KB | Output is correct |
7 | Correct | 131 ms | 30004 KB | Output is correct |
8 | Correct | 1 ms | 348 KB | Output is correct |
9 | Correct | 31 ms | 9652 KB | Output is correct |
10 | Correct | 123 ms | 30004 KB | Output is correct |
11 | Correct | 119 ms | 30008 KB | Output is correct |
12 | Correct | 171 ms | 29992 KB | Output is correct |
13 | Correct | 0 ms | 348 KB | Output is correct |
14 | Incorrect | 0 ms | 348 KB | Answer gives possible 0 while actual possible 1 |
15 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 392 KB | Output is correct |
5 | Correct | 1 ms | 348 KB | Output is correct |
6 | Correct | 11 ms | 2908 KB | Output is correct |
7 | Correct | 172 ms | 30036 KB | Output is correct |
8 | Correct | 1 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Correct | 1 ms | 348 KB | Output is correct |
11 | Correct | 0 ms | 348 KB | Output is correct |
12 | Correct | 5 ms | 2908 KB | Output is correct |
13 | Correct | 139 ms | 29992 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 0 ms | 348 KB | Output is correct |
16 | Correct | 3 ms | 2396 KB | Output is correct |
17 | Correct | 87 ms | 20020 KB | Output is correct |
18 | Correct | 0 ms | 348 KB | Output is correct |
19 | Correct | 0 ms | 344 KB | Output is correct |
20 | Correct | 32 ms | 9868 KB | Output is correct |
21 | Correct | 123 ms | 30036 KB | Output is correct |
22 | Correct | 121 ms | 30036 KB | Output is correct |
23 | Correct | 156 ms | 29988 KB | Output is correct |
24 | Correct | 121 ms | 30008 KB | Output is correct |
25 | Correct | 62 ms | 20056 KB | Output is correct |
26 | Correct | 54 ms | 20052 KB | Output is correct |
27 | Correct | 154 ms | 30040 KB | Output is correct |
28 | Correct | 135 ms | 30016 KB | Output is correct |
29 | Correct | 0 ms | 348 KB | Output is correct |
30 | Correct | 0 ms | 348 KB | Output is correct |
31 | Correct | 1 ms | 348 KB | Output is correct |
32 | Correct | 0 ms | 348 KB | Output is correct |
33 | Correct | 0 ms | 348 KB | Output is correct |
34 | Correct | 1 ms | 348 KB | Output is correct |
35 | Correct | 1 ms | 348 KB | Output is correct |
36 | Correct | 6 ms | 2908 KB | Output is correct |
37 | Correct | 125 ms | 30008 KB | Output is correct |
38 | Correct | 1 ms | 344 KB | Output is correct |
39 | Correct | 1 ms | 348 KB | Output is correct |
40 | Correct | 6 ms | 2908 KB | Output is correct |
41 | Correct | 136 ms | 29888 KB | Output is correct |
42 | Correct | 0 ms | 348 KB | Output is correct |
43 | Correct | 1 ms | 348 KB | Output is correct |
44 | Correct | 3 ms | 2396 KB | Output is correct |
45 | Correct | 64 ms | 20048 KB | Output is correct |
46 | Correct | 0 ms | 348 KB | Output is correct |
47 | Correct | 1 ms | 348 KB | Output is correct |
48 | Correct | 0 ms | 348 KB | Output is correct |
49 | Correct | 36 ms | 10204 KB | Output is correct |
50 | Correct | 131 ms | 31228 KB | Output is correct |
51 | Correct | 126 ms | 31316 KB | Output is correct |
52 | Correct | 158 ms | 31220 KB | Output is correct |
53 | Correct | 59 ms | 17312 KB | Output is correct |
54 | Correct | 61 ms | 21328 KB | Output is correct |
55 | Correct | 122 ms | 31236 KB | Output is correct |
56 | Correct | 132 ms | 31284 KB | Output is correct |
57 | Correct | 57 ms | 17232 KB | Output is correct |
58 | Correct | 0 ms | 344 KB | Output is correct |
59 | Correct | 0 ms | 348 KB | Output is correct |
60 | Correct | 4 ms | 2396 KB | Output is correct |
61 | Correct | 60 ms | 21352 KB | Output is correct |
62 | Correct | 0 ms | 348 KB | Output is correct |
63 | Incorrect | 0 ms | 468 KB | Answer gives possible 0 while actual possible 1 |
64 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 392 KB | Output is correct |
5 | Correct | 1 ms | 348 KB | Output is correct |
6 | Correct | 11 ms | 2908 KB | Output is correct |
7 | Correct | 172 ms | 30036 KB | Output is correct |
8 | Correct | 1 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Correct | 1 ms | 348 KB | Output is correct |
11 | Correct | 0 ms | 348 KB | Output is correct |
12 | Correct | 5 ms | 2908 KB | Output is correct |
13 | Correct | 139 ms | 29992 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 0 ms | 348 KB | Output is correct |
16 | Correct | 3 ms | 2396 KB | Output is correct |
17 | Correct | 87 ms | 20020 KB | Output is correct |
18 | Correct | 0 ms | 348 KB | Output is correct |
19 | Correct | 0 ms | 344 KB | Output is correct |
20 | Correct | 32 ms | 9868 KB | Output is correct |
21 | Correct | 123 ms | 30036 KB | Output is correct |
22 | Correct | 121 ms | 30036 KB | Output is correct |
23 | Correct | 156 ms | 29988 KB | Output is correct |
24 | Correct | 121 ms | 30008 KB | Output is correct |
25 | Correct | 62 ms | 20056 KB | Output is correct |
26 | Correct | 54 ms | 20052 KB | Output is correct |
27 | Correct | 154 ms | 30040 KB | Output is correct |
28 | Correct | 135 ms | 30016 KB | Output is correct |
29 | Correct | 0 ms | 348 KB | Output is correct |
30 | Correct | 0 ms | 348 KB | Output is correct |
31 | Correct | 1 ms | 348 KB | Output is correct |
32 | Correct | 0 ms | 348 KB | Output is correct |
33 | Correct | 0 ms | 348 KB | Output is correct |
34 | Correct | 1 ms | 348 KB | Output is correct |
35 | Correct | 1 ms | 348 KB | Output is correct |
36 | Correct | 6 ms | 2908 KB | Output is correct |
37 | Correct | 125 ms | 30008 KB | Output is correct |
38 | Correct | 1 ms | 344 KB | Output is correct |
39 | Correct | 1 ms | 348 KB | Output is correct |
40 | Correct | 6 ms | 2908 KB | Output is correct |
41 | Correct | 136 ms | 29888 KB | Output is correct |
42 | Correct | 0 ms | 348 KB | Output is correct |
43 | Correct | 1 ms | 348 KB | Output is correct |
44 | Correct | 3 ms | 2396 KB | Output is correct |
45 | Correct | 64 ms | 20048 KB | Output is correct |
46 | Correct | 0 ms | 348 KB | Output is correct |
47 | Correct | 1 ms | 348 KB | Output is correct |
48 | Correct | 0 ms | 348 KB | Output is correct |
49 | Correct | 36 ms | 10204 KB | Output is correct |
50 | Correct | 131 ms | 31228 KB | Output is correct |
51 | Correct | 126 ms | 31316 KB | Output is correct |
52 | Correct | 158 ms | 31220 KB | Output is correct |
53 | Correct | 59 ms | 17312 KB | Output is correct |
54 | Correct | 61 ms | 21328 KB | Output is correct |
55 | Correct | 122 ms | 31236 KB | Output is correct |
56 | Correct | 132 ms | 31284 KB | Output is correct |
57 | Correct | 57 ms | 17232 KB | Output is correct |
58 | Correct | 0 ms | 348 KB | Output is correct |
59 | Correct | 0 ms | 348 KB | Output is correct |
60 | Correct | 0 ms | 348 KB | Output is correct |
61 | Correct | 32 ms | 9696 KB | Output is correct |
62 | Correct | 119 ms | 30000 KB | Output is correct |
63 | Correct | 120 ms | 30032 KB | Output is correct |
64 | Correct | 131 ms | 30004 KB | Output is correct |
65 | Correct | 1 ms | 348 KB | Output is correct |
66 | Correct | 31 ms | 9652 KB | Output is correct |
67 | Correct | 123 ms | 30004 KB | Output is correct |
68 | Correct | 119 ms | 30008 KB | Output is correct |
69 | Correct | 171 ms | 29992 KB | Output is correct |
70 | Correct | 0 ms | 348 KB | Output is correct |
71 | Incorrect | 0 ms | 348 KB | Answer gives possible 0 while actual possible 1 |
72 | Halted | 0 ms | 0 KB | - |