답안 #798206

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
798206 2023-07-30T13:29:37 Z HaroldVemeno 슈퍼트리 잇기 (IOI20_supertrees) C++17
100 / 100
186 ms 23616 KB
#include "supertrees.h"
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int n;
vector<vector<int>> am;
vector<vector<int>> res;
vector<int> comp;
int compn = 0;
vector<int> tv;
int tvn = 0;

int construct(vector<vector<int>> p) {
	n = p.size();
    am = std::move(p);
    comp.resize(n, -1);
    res.resize(n, vector<int>(n, 0));
    tv.resize(n, -1);
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < n; ++j) {
            if(am[i][j] == 3) {
                return 0;
            }
            if(am[i][j] != am[j][i]) {
                return 0;
            }
        }
    }
    for(int i = 0; i < n; ++i) {
        if(am[i][i] != 1) return 0;
        res[i][i] = 1;
    }
    vector<vector<int>> comps;
    for(int i = 0; i < n; ++i) {
        if(comp[i] != -1) continue;
        comp[i] = compn++;
        comps.push_back({i});
        for(int j = 0; j < n; ++j) {
            if(i == j) continue;
            if(am[i][j] > 0) {
                comp[j] = comp[i];
                comps[comp[i]].push_back(j);
            }
        }
    }
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < n; ++j) {
            if((comp[i] == comp[j]) != (am[i][j] > 0)) {
                return 0;
            }
        }
    }
    vector<vector<int>> tvbycomps(compn);
    vector<vector<int>> ts;
    for(int i = 0; i < n; ++i) {
        if(tv[i] != -1) continue;
        tv[i] = tvn++;
        ts.push_back({i});
        tvbycomps[comp[i]].push_back(i);
        for(int j = 0; j < n; ++j) {
            if(i == j) continue;
            if(am[i][j] == 1) {
                tv[j] = tv[i];
                res[i][j] = 1;
                res[j][i] = 1;
                ts[tv[i]].push_back(j);
            }
        }
    }
    for(auto& c : comps) {
        for(int a : c) {
            for(int b : c) {
                if((tv[a] == tv[b]) != (am[a][b] == 1)) {
                    return 0;
                }
                if((tv[a] != tv[b]) != (am[a][b] == 2)) {
                    return 0;
                }
            }
        }
    }

    for(auto& cts : tvbycomps) {
        if(cts.size() == 1) continue;
        if(cts.size() == 2) return 0;
        for(int i = 0; i < cts.size()-1; ++i) {
            res[cts[i]][cts[i+1]] = 1;
            res[cts[i+1]][cts[i]] = 1;
        }
        res[cts[0]][cts.back()] = 1;
        res[cts.back()][cts[0]] = 1;
    }

    for(int i = 0; i < n; ++i) {
        res[i][i] = 0;
    }
    build(res);

	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:88:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |         for(int i = 0; i < cts.size()-1; ++i) {
      |                        ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1176 KB Output is correct
7 Correct 152 ms 23380 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 1 ms 308 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1176 KB Output is correct
7 Correct 152 ms 23380 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 6 ms 1276 KB Output is correct
13 Correct 152 ms 23600 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 852 KB Output is correct
17 Correct 72 ms 13560 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 38 ms 6188 KB Output is correct
21 Correct 155 ms 23372 KB Output is correct
22 Correct 160 ms 23492 KB Output is correct
23 Correct 158 ms 23372 KB Output is correct
24 Correct 152 ms 23536 KB Output is correct
25 Correct 64 ms 13460 KB Output is correct
26 Correct 65 ms 13520 KB Output is correct
27 Correct 157 ms 23396 KB Output is correct
28 Correct 161 ms 23508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 7 ms 1236 KB Output is correct
9 Correct 159 ms 23616 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 300 KB Output is correct
12 Correct 7 ms 1236 KB Output is correct
13 Correct 156 ms 23428 KB Output is correct
14 Correct 1 ms 300 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 70 ms 13580 KB Output is correct
18 Correct 1 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 38 ms 6184 KB Output is correct
22 Correct 156 ms 23436 KB Output is correct
23 Correct 155 ms 23584 KB Output is correct
24 Correct 157 ms 23532 KB Output is correct
25 Correct 64 ms 13696 KB Output is correct
26 Correct 63 ms 13464 KB Output is correct
27 Correct 151 ms 23452 KB Output is correct
28 Correct 158 ms 23524 KB Output is correct
29 Correct 66 ms 13624 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 37 ms 6240 KB Output is correct
5 Correct 153 ms 23464 KB Output is correct
6 Correct 186 ms 23536 KB Output is correct
7 Correct 158 ms 23436 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 41 ms 6204 KB Output is correct
10 Correct 156 ms 23488 KB Output is correct
11 Correct 151 ms 23516 KB Output is correct
12 Correct 163 ms 23468 KB Output is correct
13 Correct 1 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 39 ms 6260 KB Output is correct
17 Correct 153 ms 23408 KB Output is correct
18 Correct 155 ms 23512 KB Output is correct
19 Correct 151 ms 23484 KB Output is correct
20 Correct 153 ms 23536 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 1 ms 308 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1176 KB Output is correct
7 Correct 152 ms 23380 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 6 ms 1276 KB Output is correct
13 Correct 152 ms 23600 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 852 KB Output is correct
17 Correct 72 ms 13560 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 38 ms 6188 KB Output is correct
21 Correct 155 ms 23372 KB Output is correct
22 Correct 160 ms 23492 KB Output is correct
23 Correct 158 ms 23372 KB Output is correct
24 Correct 152 ms 23536 KB Output is correct
25 Correct 64 ms 13460 KB Output is correct
26 Correct 65 ms 13520 KB Output is correct
27 Correct 157 ms 23396 KB Output is correct
28 Correct 161 ms 23508 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 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 1 ms 300 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 7 ms 1236 KB Output is correct
37 Correct 159 ms 23616 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 0 ms 300 KB Output is correct
40 Correct 7 ms 1236 KB Output is correct
41 Correct 156 ms 23428 KB Output is correct
42 Correct 1 ms 300 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 3 ms 852 KB Output is correct
45 Correct 70 ms 13580 KB Output is correct
46 Correct 1 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 38 ms 6184 KB Output is correct
50 Correct 156 ms 23436 KB Output is correct
51 Correct 155 ms 23584 KB Output is correct
52 Correct 157 ms 23532 KB Output is correct
53 Correct 64 ms 13696 KB Output is correct
54 Correct 63 ms 13464 KB Output is correct
55 Correct 151 ms 23452 KB Output is correct
56 Correct 158 ms 23524 KB Output is correct
57 Correct 66 ms 13624 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 0 ms 296 KB Output is correct
60 Correct 5 ms 820 KB Output is correct
61 Correct 75 ms 13576 KB Output is correct
62 Correct 0 ms 212 KB Output is correct
63 Correct 0 ms 212 KB Output is correct
64 Correct 1 ms 212 KB Output is correct
65 Correct 38 ms 6216 KB Output is correct
66 Correct 66 ms 13456 KB Output is correct
67 Correct 67 ms 13484 KB Output is correct
68 Correct 63 ms 13536 KB Output is correct
69 Correct 68 ms 13652 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 1 ms 308 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1176 KB Output is correct
7 Correct 152 ms 23380 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 6 ms 1276 KB Output is correct
13 Correct 152 ms 23600 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 852 KB Output is correct
17 Correct 72 ms 13560 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 38 ms 6188 KB Output is correct
21 Correct 155 ms 23372 KB Output is correct
22 Correct 160 ms 23492 KB Output is correct
23 Correct 158 ms 23372 KB Output is correct
24 Correct 152 ms 23536 KB Output is correct
25 Correct 64 ms 13460 KB Output is correct
26 Correct 65 ms 13520 KB Output is correct
27 Correct 157 ms 23396 KB Output is correct
28 Correct 161 ms 23508 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 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 1 ms 300 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 7 ms 1236 KB Output is correct
37 Correct 159 ms 23616 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 0 ms 300 KB Output is correct
40 Correct 7 ms 1236 KB Output is correct
41 Correct 156 ms 23428 KB Output is correct
42 Correct 1 ms 300 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 3 ms 852 KB Output is correct
45 Correct 70 ms 13580 KB Output is correct
46 Correct 1 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 38 ms 6184 KB Output is correct
50 Correct 156 ms 23436 KB Output is correct
51 Correct 155 ms 23584 KB Output is correct
52 Correct 157 ms 23532 KB Output is correct
53 Correct 64 ms 13696 KB Output is correct
54 Correct 63 ms 13464 KB Output is correct
55 Correct 151 ms 23452 KB Output is correct
56 Correct 158 ms 23524 KB Output is correct
57 Correct 66 ms 13624 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 37 ms 6240 KB Output is correct
62 Correct 153 ms 23464 KB Output is correct
63 Correct 186 ms 23536 KB Output is correct
64 Correct 158 ms 23436 KB Output is correct
65 Correct 1 ms 212 KB Output is correct
66 Correct 41 ms 6204 KB Output is correct
67 Correct 156 ms 23488 KB Output is correct
68 Correct 151 ms 23516 KB Output is correct
69 Correct 163 ms 23468 KB Output is correct
70 Correct 1 ms 212 KB Output is correct
71 Correct 0 ms 212 KB Output is correct
72 Correct 0 ms 212 KB Output is correct
73 Correct 39 ms 6260 KB Output is correct
74 Correct 153 ms 23408 KB Output is correct
75 Correct 155 ms 23512 KB Output is correct
76 Correct 151 ms 23484 KB Output is correct
77 Correct 153 ms 23536 KB Output is correct
78 Correct 0 ms 212 KB Output is correct
79 Correct 0 ms 296 KB Output is correct
80 Correct 5 ms 820 KB Output is correct
81 Correct 75 ms 13576 KB Output is correct
82 Correct 0 ms 212 KB Output is correct
83 Correct 0 ms 212 KB Output is correct
84 Correct 1 ms 212 KB Output is correct
85 Correct 38 ms 6216 KB Output is correct
86 Correct 66 ms 13456 KB Output is correct
87 Correct 67 ms 13484 KB Output is correct
88 Correct 63 ms 13536 KB Output is correct
89 Correct 68 ms 13652 KB Output is correct
90 Correct 1 ms 212 KB Output is correct
91 Correct 1 ms 212 KB Output is correct
92 Correct 3 ms 828 KB Output is correct
93 Correct 63 ms 13464 KB Output is correct
94 Correct 1 ms 212 KB Output is correct
95 Correct 0 ms 212 KB Output is correct
96 Correct 0 ms 212 KB Output is correct
97 Correct 16 ms 3708 KB Output is correct
98 Correct 71 ms 13608 KB Output is correct
99 Correct 64 ms 13584 KB Output is correct
100 Correct 63 ms 13680 KB Output is correct
101 Correct 60 ms 13652 KB Output is correct
102 Correct 59 ms 13576 KB Output is correct
103 Correct 63 ms 13604 KB Output is correct
104 Correct 62 ms 13496 KB Output is correct
105 Correct 64 ms 13548 KB Output is correct