답안 #535414

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
535414 2022-03-10T09:05:23 Z mario05092929 슈퍼트리 잇기 (IOI20_supertrees) C++14
100 / 100
198 ms 28072 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
int n,p[1005],p2[1005],c[1005];
vector <vector <int>> v,A;
vector <int> g;

int Find(int x) {return (x^p[x] ? p[x] = Find(p[x]) : x);}
int Find2(int x) {return (x^p2[x] ? p2[x] = Find2(p2[x]) : x);}

void merge(int x,int y) {
    if(Find(x) == Find(y)) return;
    v[x][y] = v[y][x] = 1;
    p[p[y]] = p[x];
}

void merge2(int x,int y) {
    x = Find2(x), y = Find2(y);
    if(x == y) return;
    p2[y] = x;
}

void dfs(int x) {
    g.push_back(x);
    c[x] = 1;
    for(int i = 0;i < n;i++) {
        if(A[x][i] == 2&&Find(i) == i&&!c[i]) dfs(i);
    }
}

int construct(std::vector<std::vector<int>> B) {
    A = B;
    n = A.size();
	v.resize(n);
	for(int i = 0;i < n;i++) v[i].resize(n,0);
	for(int i = 0;i < n;i++) p[i] = p2[i] = i;
    for(int i = 0;i < n;i++) {
        for(int j = i+1;j < n;j++) {
            if(A[i][j] == 3) return 0;
            if(A[i][j] == 1) merge(i,j);
            if(A[i][j]) merge2(i,j);
        }
    }
    for(int i = 0;i < n;i++) {
        if(!c[i]&&Find(i) == i) {
            g.clear();
            dfs(i);
            if(g.size() == 1) continue;
            if(g.size() == 2) return 0;
            g.push_back(i);
            for(int j = 0;j < g.size()-1;j++) v[g[j]][g[j+1]] = v[g[j+1]][g[j]] = 1;
        }
    }
    for(int i = 0;i < n;i++) {
        for(int j = i+1;j < n;j++) {
            if(Find(i) == Find(j)) {
                if(A[i][j]^1) return 0;
            }
            else if(Find2(i) == Find2(j)) {
                if(A[i][j]^2) return 0;
            }
            else if(A[i][j]) return 0;
        }
    }
    build(v);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:51:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |             for(int j = 0;j < g.size()-1;j++) v[g[j]][g[j+1]] = v[g[j+1]][g[j]] = 1;
      |                           ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 308 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 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 195 ms 27900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 308 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 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 195 ms 27900 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 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 9 ms 1384 KB Output is correct
13 Correct 175 ms 27944 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 980 KB Output is correct
17 Correct 93 ms 18040 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 53 ms 7168 KB Output is correct
21 Correct 192 ms 27900 KB Output is correct
22 Correct 165 ms 27908 KB Output is correct
23 Correct 197 ms 27964 KB Output is correct
24 Correct 167 ms 27872 KB Output is correct
25 Correct 73 ms 18040 KB Output is correct
26 Correct 69 ms 18056 KB Output is correct
27 Correct 194 ms 27936 KB Output is correct
28 Correct 174 ms 27980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 304 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 308 KB Output is correct
8 Correct 9 ms 1364 KB Output is correct
9 Correct 167 ms 27960 KB Output is correct
10 Correct 0 ms 304 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 8 ms 1340 KB Output is correct
13 Correct 188 ms 28032 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 5 ms 980 KB Output is correct
17 Correct 105 ms 18044 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 45 ms 7160 KB Output is correct
22 Correct 178 ms 27908 KB Output is correct
23 Correct 168 ms 27936 KB Output is correct
24 Correct 195 ms 27980 KB Output is correct
25 Correct 70 ms 17972 KB Output is correct
26 Correct 73 ms 18056 KB Output is correct
27 Correct 171 ms 27904 KB Output is correct
28 Correct 191 ms 27980 KB Output is correct
29 Correct 70 ms 18056 KB Output is correct
# 결과 실행 시간 메모리 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 Correct 45 ms 7244 KB Output is correct
5 Correct 175 ms 27980 KB Output is correct
6 Correct 170 ms 27896 KB Output is correct
7 Correct 198 ms 27900 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 49 ms 7160 KB Output is correct
10 Correct 175 ms 27936 KB Output is correct
11 Correct 171 ms 27908 KB Output is correct
12 Correct 194 ms 27916 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 312 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 49 ms 7180 KB Output is correct
17 Correct 182 ms 27920 KB Output is correct
18 Correct 178 ms 28072 KB Output is correct
19 Correct 173 ms 27908 KB Output is correct
20 Correct 166 ms 27944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 308 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 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 195 ms 27900 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 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 9 ms 1384 KB Output is correct
13 Correct 175 ms 27944 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 980 KB Output is correct
17 Correct 93 ms 18040 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 53 ms 7168 KB Output is correct
21 Correct 192 ms 27900 KB Output is correct
22 Correct 165 ms 27908 KB Output is correct
23 Correct 197 ms 27964 KB Output is correct
24 Correct 167 ms 27872 KB Output is correct
25 Correct 73 ms 18040 KB Output is correct
26 Correct 69 ms 18056 KB Output is correct
27 Correct 194 ms 27936 KB Output is correct
28 Correct 174 ms 27980 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 304 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 308 KB Output is correct
36 Correct 9 ms 1364 KB Output is correct
37 Correct 167 ms 27960 KB Output is correct
38 Correct 0 ms 304 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 8 ms 1340 KB Output is correct
41 Correct 188 ms 28032 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 5 ms 980 KB Output is correct
45 Correct 105 ms 18044 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 45 ms 7160 KB Output is correct
50 Correct 178 ms 27908 KB Output is correct
51 Correct 168 ms 27936 KB Output is correct
52 Correct 195 ms 27980 KB Output is correct
53 Correct 70 ms 17972 KB Output is correct
54 Correct 73 ms 18056 KB Output is correct
55 Correct 171 ms 27904 KB Output is correct
56 Correct 191 ms 27980 KB Output is correct
57 Correct 70 ms 18056 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 0 ms 304 KB Output is correct
60 Correct 5 ms 980 KB Output is correct
61 Correct 97 ms 18060 KB Output is correct
62 Correct 0 ms 212 KB Output is correct
63 Correct 1 ms 212 KB Output is correct
64 Correct 1 ms 212 KB Output is correct
65 Correct 45 ms 7148 KB Output is correct
66 Correct 73 ms 18044 KB Output is correct
67 Correct 74 ms 17996 KB Output is correct
68 Correct 69 ms 18056 KB Output is correct
69 Correct 69 ms 18124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 308 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 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 195 ms 27900 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 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 9 ms 1384 KB Output is correct
13 Correct 175 ms 27944 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 980 KB Output is correct
17 Correct 93 ms 18040 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 53 ms 7168 KB Output is correct
21 Correct 192 ms 27900 KB Output is correct
22 Correct 165 ms 27908 KB Output is correct
23 Correct 197 ms 27964 KB Output is correct
24 Correct 167 ms 27872 KB Output is correct
25 Correct 73 ms 18040 KB Output is correct
26 Correct 69 ms 18056 KB Output is correct
27 Correct 194 ms 27936 KB Output is correct
28 Correct 174 ms 27980 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 304 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 308 KB Output is correct
36 Correct 9 ms 1364 KB Output is correct
37 Correct 167 ms 27960 KB Output is correct
38 Correct 0 ms 304 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 8 ms 1340 KB Output is correct
41 Correct 188 ms 28032 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 5 ms 980 KB Output is correct
45 Correct 105 ms 18044 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 45 ms 7160 KB Output is correct
50 Correct 178 ms 27908 KB Output is correct
51 Correct 168 ms 27936 KB Output is correct
52 Correct 195 ms 27980 KB Output is correct
53 Correct 70 ms 17972 KB Output is correct
54 Correct 73 ms 18056 KB Output is correct
55 Correct 171 ms 27904 KB Output is correct
56 Correct 191 ms 27980 KB Output is correct
57 Correct 70 ms 18056 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 45 ms 7244 KB Output is correct
62 Correct 175 ms 27980 KB Output is correct
63 Correct 170 ms 27896 KB Output is correct
64 Correct 198 ms 27900 KB Output is correct
65 Correct 0 ms 212 KB Output is correct
66 Correct 49 ms 7160 KB Output is correct
67 Correct 175 ms 27936 KB Output is correct
68 Correct 171 ms 27908 KB Output is correct
69 Correct 194 ms 27916 KB Output is correct
70 Correct 0 ms 212 KB Output is correct
71 Correct 0 ms 312 KB Output is correct
72 Correct 1 ms 212 KB Output is correct
73 Correct 49 ms 7180 KB Output is correct
74 Correct 182 ms 27920 KB Output is correct
75 Correct 178 ms 28072 KB Output is correct
76 Correct 173 ms 27908 KB Output is correct
77 Correct 166 ms 27944 KB Output is correct
78 Correct 0 ms 212 KB Output is correct
79 Correct 0 ms 304 KB Output is correct
80 Correct 5 ms 980 KB Output is correct
81 Correct 97 ms 18060 KB Output is correct
82 Correct 0 ms 212 KB Output is correct
83 Correct 1 ms 212 KB Output is correct
84 Correct 1 ms 212 KB Output is correct
85 Correct 45 ms 7148 KB Output is correct
86 Correct 73 ms 18044 KB Output is correct
87 Correct 74 ms 17996 KB Output is correct
88 Correct 69 ms 18056 KB Output is correct
89 Correct 69 ms 18124 KB Output is correct
90 Correct 0 ms 212 KB Output is correct
91 Correct 1 ms 212 KB Output is correct
92 Correct 4 ms 980 KB Output is correct
93 Correct 89 ms 17968 KB Output is correct
94 Correct 0 ms 212 KB Output is correct
95 Correct 1 ms 212 KB Output is correct
96 Correct 0 ms 212 KB Output is correct
97 Correct 18 ms 4736 KB Output is correct
98 Correct 72 ms 18044 KB Output is correct
99 Correct 80 ms 18048 KB Output is correct
100 Correct 69 ms 17996 KB Output is correct
101 Correct 68 ms 18040 KB Output is correct
102 Correct 85 ms 18044 KB Output is correct
103 Correct 84 ms 17984 KB Output is correct
104 Correct 86 ms 18048 KB Output is correct
105 Correct 89 ms 18060 KB Output is correct