답안 #1062494

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1062494 2024-08-17T07:55:09 Z new_acc 슈퍼트리 잇기 (IOI20_supertrees) C++14
100 / 100
150 ms 24148 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const int N=1e4+10;
int fau[N],fau2[N];
bool vis[N];
vi kt[N];
int Find(int a){
    if(fau[a]==a) return a;
    return fau[a]=Find(fau[a]);
}
void Union(int a,int b){
    a=Find(a),b=Find(b);
    fau[a]=b;
}
int Find2(int a){
    if(fau2[a]==a) return a;
    return fau2[a]=Find2(fau2[a]);
}
void Union2(int a,int b){
    a=Find2(a),b=Find2(b);
    fau2[a]=fau2[b];
}
int construct(vector<vi> g) {
    int n=g.size();
    iota(fau,fau+1+n,0);
    iota(fau2,fau2+1+n,0);
    vector<vi> ans=g;
    for(int i=0;i<n;i++){
        for(int i2=0;i2<n;i2++) ans[i][i2]=0;
    }
    for(int i=0;i<n;i++){
        for(int i2=0;i2<n;i2++){
            if(g[i][i2]==1) Union(i+1,i2+1);
        }
    } 
    for(int i=0;i<n;i++){
        for(int i2=0;i2<n;i2++){
            if(g[i][i2]==2) Union2(Find(i+1),Find(i2+1));
        }
    }
    for(int i=1;i<=n;i++){
        int u=Find(i);               
        if(vis[u]) continue;
        vis[u]=1;
        kt[Find2(u)].push_back(u);
    }
    for(int i=1;i<=n;i++){
        if(kt[i].size()==2){
            return 0;
        }
        if(kt[i].size()<2) continue;
        for(int i2=0;i2<(int)kt[i].size();i2++){
            int nxt=kt[i][(i2+1)%kt[i].size()],u=kt[i][i2];
            ans[u-1][nxt-1]=1,ans[nxt-1][u-1]=1;
        }
    }
    for(int i=1;i<=n;i++){
        int u=Find(i);
        if(u!=i) ans[u-1][i-1]=1,ans[i-1][u-1]=1;
    }
    for(int i=0;i<n;i++){
        for(int i2=0;i2<n;i2++){
            int u=Find(i+1),u2=Find(i2+1);
            int v1=Find2(u),v2=Find2(u2);
            if(g[i][i2]==0){
                if(u==u2 or v1==v2) return 0;
            }
            if(g[i][i2]==1){
                if(u!=u2) return 0;
            }
            if(g[i][i2]==2){
                if(u==u2 or v1!=v2) return 0;
            }
            if(g[i][i2]==3) return 0;
        }
    }
    build(ans);
	return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 5 ms 1624 KB Output is correct
7 Correct 120 ms 24140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 5 ms 1624 KB Output is correct
7 Correct 120 ms 24140 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 0 ms 680 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 10 ms 1656 KB Output is correct
13 Correct 115 ms 24140 KB Output is correct
14 Correct 0 ms 600 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 3 ms 1204 KB Output is correct
17 Correct 67 ms 14076 KB Output is correct
18 Correct 0 ms 604 KB Output is correct
19 Correct 0 ms 604 KB Output is correct
20 Correct 30 ms 6568 KB Output is correct
21 Correct 117 ms 24148 KB Output is correct
22 Correct 115 ms 24144 KB Output is correct
23 Correct 127 ms 24144 KB Output is correct
24 Correct 116 ms 24144 KB Output is correct
25 Correct 60 ms 14252 KB Output is correct
26 Correct 51 ms 14288 KB Output is correct
27 Correct 126 ms 24148 KB Output is correct
28 Correct 115 ms 24148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 5 ms 1428 KB Output is correct
9 Correct 115 ms 23752 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 5 ms 1628 KB Output is correct
13 Correct 123 ms 23540 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 3 ms 1116 KB Output is correct
17 Correct 65 ms 13772 KB Output is correct
18 Correct 0 ms 600 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 0 ms 604 KB Output is correct
21 Correct 30 ms 6520 KB Output is correct
22 Correct 119 ms 24148 KB Output is correct
23 Correct 117 ms 24148 KB Output is correct
24 Correct 143 ms 24148 KB Output is correct
25 Correct 50 ms 14164 KB Output is correct
26 Correct 53 ms 14200 KB Output is correct
27 Correct 120 ms 24044 KB Output is correct
28 Correct 131 ms 24148 KB Output is correct
29 Correct 50 ms 14160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 30 ms 6588 KB Output is correct
5 Correct 150 ms 23708 KB Output is correct
6 Correct 125 ms 23496 KB Output is correct
7 Correct 138 ms 23664 KB Output is correct
8 Correct 1 ms 856 KB Output is correct
9 Correct 30 ms 6480 KB Output is correct
10 Correct 122 ms 24056 KB Output is correct
11 Correct 123 ms 24092 KB Output is correct
12 Correct 124 ms 24144 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 0 ms 680 KB Output is correct
16 Correct 33 ms 6520 KB Output is correct
17 Correct 122 ms 24144 KB Output is correct
18 Correct 128 ms 24144 KB Output is correct
19 Correct 123 ms 24144 KB Output is correct
20 Correct 116 ms 24148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 5 ms 1624 KB Output is correct
7 Correct 120 ms 24140 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 0 ms 680 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 10 ms 1656 KB Output is correct
13 Correct 115 ms 24140 KB Output is correct
14 Correct 0 ms 600 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 3 ms 1204 KB Output is correct
17 Correct 67 ms 14076 KB Output is correct
18 Correct 0 ms 604 KB Output is correct
19 Correct 0 ms 604 KB Output is correct
20 Correct 30 ms 6568 KB Output is correct
21 Correct 117 ms 24148 KB Output is correct
22 Correct 115 ms 24144 KB Output is correct
23 Correct 127 ms 24144 KB Output is correct
24 Correct 116 ms 24144 KB Output is correct
25 Correct 60 ms 14252 KB Output is correct
26 Correct 51 ms 14288 KB Output is correct
27 Correct 126 ms 24148 KB Output is correct
28 Correct 115 ms 24148 KB Output is correct
29 Correct 0 ms 600 KB Output is correct
30 Correct 0 ms 604 KB Output is correct
31 Correct 0 ms 604 KB Output is correct
32 Correct 0 ms 604 KB Output is correct
33 Correct 0 ms 604 KB Output is correct
34 Correct 0 ms 604 KB Output is correct
35 Correct 0 ms 604 KB Output is correct
36 Correct 5 ms 1428 KB Output is correct
37 Correct 115 ms 23752 KB Output is correct
38 Correct 1 ms 604 KB Output is correct
39 Correct 0 ms 604 KB Output is correct
40 Correct 5 ms 1628 KB Output is correct
41 Correct 123 ms 23540 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 1 ms 600 KB Output is correct
44 Correct 3 ms 1116 KB Output is correct
45 Correct 65 ms 13772 KB Output is correct
46 Correct 0 ms 600 KB Output is correct
47 Correct 1 ms 604 KB Output is correct
48 Correct 0 ms 604 KB Output is correct
49 Correct 30 ms 6520 KB Output is correct
50 Correct 119 ms 24148 KB Output is correct
51 Correct 117 ms 24148 KB Output is correct
52 Correct 143 ms 24148 KB Output is correct
53 Correct 50 ms 14164 KB Output is correct
54 Correct 53 ms 14200 KB Output is correct
55 Correct 120 ms 24044 KB Output is correct
56 Correct 131 ms 24148 KB Output is correct
57 Correct 50 ms 14160 KB Output is correct
58 Correct 0 ms 604 KB Output is correct
59 Correct 0 ms 604 KB Output is correct
60 Correct 3 ms 1116 KB Output is correct
61 Correct 63 ms 14092 KB Output is correct
62 Correct 1 ms 600 KB Output is correct
63 Correct 1 ms 604 KB Output is correct
64 Correct 0 ms 604 KB Output is correct
65 Correct 29 ms 6612 KB Output is correct
66 Correct 57 ms 14316 KB Output is correct
67 Correct 56 ms 14248 KB Output is correct
68 Correct 51 ms 14080 KB Output is correct
69 Correct 51 ms 14160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 5 ms 1624 KB Output is correct
7 Correct 120 ms 24140 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 0 ms 680 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 10 ms 1656 KB Output is correct
13 Correct 115 ms 24140 KB Output is correct
14 Correct 0 ms 600 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 3 ms 1204 KB Output is correct
17 Correct 67 ms 14076 KB Output is correct
18 Correct 0 ms 604 KB Output is correct
19 Correct 0 ms 604 KB Output is correct
20 Correct 30 ms 6568 KB Output is correct
21 Correct 117 ms 24148 KB Output is correct
22 Correct 115 ms 24144 KB Output is correct
23 Correct 127 ms 24144 KB Output is correct
24 Correct 116 ms 24144 KB Output is correct
25 Correct 60 ms 14252 KB Output is correct
26 Correct 51 ms 14288 KB Output is correct
27 Correct 126 ms 24148 KB Output is correct
28 Correct 115 ms 24148 KB Output is correct
29 Correct 0 ms 600 KB Output is correct
30 Correct 0 ms 604 KB Output is correct
31 Correct 0 ms 604 KB Output is correct
32 Correct 0 ms 604 KB Output is correct
33 Correct 0 ms 604 KB Output is correct
34 Correct 0 ms 604 KB Output is correct
35 Correct 0 ms 604 KB Output is correct
36 Correct 5 ms 1428 KB Output is correct
37 Correct 115 ms 23752 KB Output is correct
38 Correct 1 ms 604 KB Output is correct
39 Correct 0 ms 604 KB Output is correct
40 Correct 5 ms 1628 KB Output is correct
41 Correct 123 ms 23540 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 1 ms 600 KB Output is correct
44 Correct 3 ms 1116 KB Output is correct
45 Correct 65 ms 13772 KB Output is correct
46 Correct 0 ms 600 KB Output is correct
47 Correct 1 ms 604 KB Output is correct
48 Correct 0 ms 604 KB Output is correct
49 Correct 30 ms 6520 KB Output is correct
50 Correct 119 ms 24148 KB Output is correct
51 Correct 117 ms 24148 KB Output is correct
52 Correct 143 ms 24148 KB Output is correct
53 Correct 50 ms 14164 KB Output is correct
54 Correct 53 ms 14200 KB Output is correct
55 Correct 120 ms 24044 KB Output is correct
56 Correct 131 ms 24148 KB Output is correct
57 Correct 50 ms 14160 KB Output is correct
58 Correct 0 ms 604 KB Output is correct
59 Correct 0 ms 604 KB Output is correct
60 Correct 0 ms 604 KB Output is correct
61 Correct 30 ms 6588 KB Output is correct
62 Correct 150 ms 23708 KB Output is correct
63 Correct 125 ms 23496 KB Output is correct
64 Correct 138 ms 23664 KB Output is correct
65 Correct 1 ms 856 KB Output is correct
66 Correct 30 ms 6480 KB Output is correct
67 Correct 122 ms 24056 KB Output is correct
68 Correct 123 ms 24092 KB Output is correct
69 Correct 124 ms 24144 KB Output is correct
70 Correct 1 ms 600 KB Output is correct
71 Correct 1 ms 604 KB Output is correct
72 Correct 0 ms 680 KB Output is correct
73 Correct 33 ms 6520 KB Output is correct
74 Correct 122 ms 24144 KB Output is correct
75 Correct 128 ms 24144 KB Output is correct
76 Correct 123 ms 24144 KB Output is correct
77 Correct 116 ms 24148 KB Output is correct
78 Correct 0 ms 604 KB Output is correct
79 Correct 0 ms 604 KB Output is correct
80 Correct 3 ms 1116 KB Output is correct
81 Correct 63 ms 14092 KB Output is correct
82 Correct 1 ms 600 KB Output is correct
83 Correct 1 ms 604 KB Output is correct
84 Correct 0 ms 604 KB Output is correct
85 Correct 29 ms 6612 KB Output is correct
86 Correct 57 ms 14316 KB Output is correct
87 Correct 56 ms 14248 KB Output is correct
88 Correct 51 ms 14080 KB Output is correct
89 Correct 51 ms 14160 KB Output is correct
90 Correct 1 ms 604 KB Output is correct
91 Correct 0 ms 580 KB Output is correct
92 Correct 3 ms 1368 KB Output is correct
93 Correct 59 ms 14160 KB Output is correct
94 Correct 1 ms 604 KB Output is correct
95 Correct 0 ms 604 KB Output is correct
96 Correct 0 ms 604 KB Output is correct
97 Correct 13 ms 3932 KB Output is correct
98 Correct 54 ms 13652 KB Output is correct
99 Correct 53 ms 13616 KB Output is correct
100 Correct 60 ms 13660 KB Output is correct
101 Correct 53 ms 13768 KB Output is correct
102 Correct 50 ms 13784 KB Output is correct
103 Correct 56 ms 13676 KB Output is correct
104 Correct 56 ms 13648 KB Output is correct
105 Correct 57 ms 13652 KB Output is correct