답안 #808704

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
808704 2023-08-05T09:40:09 Z The_Samurai 슈퍼트리 잇기 (IOI20_supertrees) C++17
100 / 100
184 ms 23132 KB
#include "bits/stdc++.h"
#ifdef sunnatov
#include "grader.cpp"
#else
#include "supertrees.h"
#endif
 
using namespace std;
 
struct dsu {
    vector<int> p, size;
 
    void init(int n) {
        p.assign(n, 0);
        size.assign(n, 1);
        for (int i = 0; i < n; i++) p[i] = i;
    }
 
    int get(int a) {
        return p[a] == a ? a : p[a] = get(p[a]);
    }
 
    void add(int a, int b) {
        a = get(a);
        b = get(b);
        if (a == b) return;
        if (size[a] > size[b]) swap(a, b);
        size[b] += size[a];
        p[a] = b;
    }
};
 
 
int construct(std::vector<std::vector<int>> p) {
	int n = p.size();
 
    vector<vector<int>> g(n, vector<int>(n));
    dsu ds;
    ds.init(n);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (p[i][j]) {
                ds.add(i, j);
            }
            if (p[i][j] == 3) return 0;
        }
    }
    vector<bool> vis(n);
    for (int _ = 0; _ < n; _++) {
        int s = -1;
        vector<int> v;
        for (int i = 0; i < n; i++) {
            if (vis[i]) continue;
            if (s == -1) s = ds.get(i);
            if (ds.get(i) != s) continue;
            v.emplace_back(i);
        }
        if (v.empty()) break;
        for (int i = 0; i < v.size(); i++) {
            for (int j = i + 1; j < v.size(); j++) {
                if (!p[v[i]][v[j]]) return 0;
            }
        }
 
        // something
        vector<bool> another_vis(n);
        vector<int> cycle;
        for (int x: v) {
            if (another_vis[x]) continue;
            vector<int> line;
            for (int i = 0; i < n; i++) {
                if (p[x][i] == 1) line.emplace_back(i);
            }
            for (int i = 0; i < line.size(); i++) {
                for (int j = i + 1; j < line.size(); j++) {
                    if (p[line[i]][line[j]] != 1) return 0;
                }
            }
            for (int i = 1; i < line.size(); i++) g[line[i - 1]][line[i]] = g[line[i]][line[i - 1]] = 1;
            for (int y: line) another_vis[y] = true;
            cycle.emplace_back(line[0]);
        }
        if (cycle.size() == 2) return false;
        if (cycle.size() > 2) {
            for (int i = 1; i < cycle.size(); i++) g[cycle[i - 1]][cycle[i]] = g[cycle[i]][cycle[i - 1]] = 1;
            g[cycle[0]][cycle.back()] = g[cycle.back()][cycle[0]] = 1;
        }
 
 
        for (int x: v) vis[x] = true;
    }
    build(g);
 
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:59:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |         for (int i = 0; i < v.size(); i++) {
      |                         ~~^~~~~~~~~~
supertrees.cpp:60:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |             for (int j = i + 1; j < v.size(); j++) {
      |                                 ~~^~~~~~~~~~
supertrees.cpp:74:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |             for (int i = 0; i < line.size(); i++) {
      |                             ~~^~~~~~~~~~~~~
supertrees.cpp:75:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |                 for (int j = i + 1; j < line.size(); j++) {
      |                                     ~~^~~~~~~~~~~~~
supertrees.cpp:79:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |             for (int i = 1; i < line.size(); i++) g[line[i - 1]][line[i]] = g[line[i]][line[i - 1]] = 1;
      |                             ~~^~~~~~~~~~~~~
supertrees.cpp:85:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |             for (int i = 1; i < cycle.size(); i++) g[cycle[i - 1]][cycle[i]] = g[cycle[i]][cycle[i - 1]] = 1;
      |                             ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1180 KB Output is correct
7 Correct 152 ms 23012 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 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1180 KB Output is correct
7 Correct 152 ms 23012 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1208 KB Output is correct
13 Correct 178 ms 23132 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 716 KB Output is correct
17 Correct 107 ms 12636 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 38 ms 5708 KB Output is correct
21 Correct 150 ms 22460 KB Output is correct
22 Correct 154 ms 22456 KB Output is correct
23 Correct 176 ms 22624 KB Output is correct
24 Correct 184 ms 22460 KB Output is correct
25 Correct 65 ms 12532 KB Output is correct
26 Correct 70 ms 12628 KB Output is correct
27 Correct 158 ms 22464 KB Output is correct
28 Correct 171 ms 22456 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 1 ms 296 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 304 KB Output is correct
8 Correct 7 ms 1236 KB Output is correct
9 Correct 153 ms 22556 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 9 ms 1204 KB Output is correct
13 Correct 154 ms 22552 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 75 ms 12048 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 40 ms 5776 KB Output is correct
22 Correct 150 ms 22036 KB Output is correct
23 Correct 152 ms 22024 KB Output is correct
24 Correct 161 ms 22016 KB Output is correct
25 Correct 64 ms 12052 KB Output is correct
26 Correct 65 ms 12108 KB Output is correct
27 Correct 149 ms 21952 KB Output is correct
28 Correct 154 ms 21984 KB Output is correct
29 Correct 66 ms 12052 KB Output is correct
# 결과 실행 시간 메모리 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 38 ms 6252 KB Output is correct
5 Correct 179 ms 22472 KB Output is correct
6 Correct 182 ms 22552 KB Output is correct
7 Correct 157 ms 22688 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 41 ms 6256 KB Output is correct
10 Correct 158 ms 22544 KB Output is correct
11 Correct 152 ms 22476 KB Output is correct
12 Correct 160 ms 22484 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 38 ms 6260 KB Output is correct
17 Correct 152 ms 22536 KB Output is correct
18 Correct 153 ms 22476 KB Output is correct
19 Correct 156 ms 22532 KB Output is correct
20 Correct 156 ms 22564 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 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1180 KB Output is correct
7 Correct 152 ms 23012 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1208 KB Output is correct
13 Correct 178 ms 23132 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 716 KB Output is correct
17 Correct 107 ms 12636 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 38 ms 5708 KB Output is correct
21 Correct 150 ms 22460 KB Output is correct
22 Correct 154 ms 22456 KB Output is correct
23 Correct 176 ms 22624 KB Output is correct
24 Correct 184 ms 22460 KB Output is correct
25 Correct 65 ms 12532 KB Output is correct
26 Correct 70 ms 12628 KB Output is correct
27 Correct 158 ms 22464 KB Output is correct
28 Correct 171 ms 22456 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 1 ms 296 KB Output is correct
33 Correct 1 ms 304 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 304 KB Output is correct
36 Correct 7 ms 1236 KB Output is correct
37 Correct 153 ms 22556 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 9 ms 1204 KB Output is correct
41 Correct 154 ms 22552 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 3 ms 724 KB Output is correct
45 Correct 75 ms 12048 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 40 ms 5776 KB Output is correct
50 Correct 150 ms 22036 KB Output is correct
51 Correct 152 ms 22024 KB Output is correct
52 Correct 161 ms 22016 KB Output is correct
53 Correct 64 ms 12052 KB Output is correct
54 Correct 65 ms 12108 KB Output is correct
55 Correct 149 ms 21952 KB Output is correct
56 Correct 154 ms 21984 KB Output is correct
57 Correct 66 ms 12052 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 1 ms 248 KB Output is correct
60 Correct 3 ms 724 KB Output is correct
61 Correct 71 ms 12036 KB Output is correct
62 Correct 0 ms 212 KB Output is correct
63 Correct 0 ms 212 KB Output is correct
64 Correct 0 ms 212 KB Output is correct
65 Correct 38 ms 5736 KB Output is correct
66 Correct 65 ms 12040 KB Output is correct
67 Correct 68 ms 12052 KB Output is correct
68 Correct 63 ms 12048 KB Output is correct
69 Correct 63 ms 12036 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 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1180 KB Output is correct
7 Correct 152 ms 23012 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1208 KB Output is correct
13 Correct 178 ms 23132 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 716 KB Output is correct
17 Correct 107 ms 12636 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 38 ms 5708 KB Output is correct
21 Correct 150 ms 22460 KB Output is correct
22 Correct 154 ms 22456 KB Output is correct
23 Correct 176 ms 22624 KB Output is correct
24 Correct 184 ms 22460 KB Output is correct
25 Correct 65 ms 12532 KB Output is correct
26 Correct 70 ms 12628 KB Output is correct
27 Correct 158 ms 22464 KB Output is correct
28 Correct 171 ms 22456 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 1 ms 296 KB Output is correct
33 Correct 1 ms 304 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 304 KB Output is correct
36 Correct 7 ms 1236 KB Output is correct
37 Correct 153 ms 22556 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 9 ms 1204 KB Output is correct
41 Correct 154 ms 22552 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 3 ms 724 KB Output is correct
45 Correct 75 ms 12048 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 40 ms 5776 KB Output is correct
50 Correct 150 ms 22036 KB Output is correct
51 Correct 152 ms 22024 KB Output is correct
52 Correct 161 ms 22016 KB Output is correct
53 Correct 64 ms 12052 KB Output is correct
54 Correct 65 ms 12108 KB Output is correct
55 Correct 149 ms 21952 KB Output is correct
56 Correct 154 ms 21984 KB Output is correct
57 Correct 66 ms 12052 KB Output is correct
58 Correct 1 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 38 ms 6252 KB Output is correct
62 Correct 179 ms 22472 KB Output is correct
63 Correct 182 ms 22552 KB Output is correct
64 Correct 157 ms 22688 KB Output is correct
65 Correct 1 ms 212 KB Output is correct
66 Correct 41 ms 6256 KB Output is correct
67 Correct 158 ms 22544 KB Output is correct
68 Correct 152 ms 22476 KB Output is correct
69 Correct 160 ms 22484 KB Output is correct
70 Correct 1 ms 212 KB Output is correct
71 Correct 0 ms 212 KB Output is correct
72 Correct 1 ms 212 KB Output is correct
73 Correct 38 ms 6260 KB Output is correct
74 Correct 152 ms 22536 KB Output is correct
75 Correct 153 ms 22476 KB Output is correct
76 Correct 156 ms 22532 KB Output is correct
77 Correct 156 ms 22564 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 1 ms 248 KB Output is correct
80 Correct 3 ms 724 KB Output is correct
81 Correct 71 ms 12036 KB Output is correct
82 Correct 0 ms 212 KB Output is correct
83 Correct 0 ms 212 KB Output is correct
84 Correct 0 ms 212 KB Output is correct
85 Correct 38 ms 5736 KB Output is correct
86 Correct 65 ms 12040 KB Output is correct
87 Correct 68 ms 12052 KB Output is correct
88 Correct 63 ms 12048 KB Output is correct
89 Correct 63 ms 12036 KB Output is correct
90 Correct 0 ms 212 KB Output is correct
91 Correct 0 ms 212 KB Output is correct
92 Correct 3 ms 724 KB Output is correct
93 Correct 63 ms 12032 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 16 ms 3156 KB Output is correct
98 Correct 62 ms 12108 KB Output is correct
99 Correct 66 ms 12032 KB Output is correct
100 Correct 63 ms 12040 KB Output is correct
101 Correct 62 ms 12032 KB Output is correct
102 Correct 64 ms 12064 KB Output is correct
103 Correct 62 ms 12036 KB Output is correct
104 Correct 60 ms 12036 KB Output is correct
105 Correct 66 ms 12052 KB Output is correct