답안 #1073411

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1073411 2024-08-24T14:20:10 Z blushingecchigirl 슈퍼트리 잇기 (IOI20_supertrees) C++17
40 / 100
184 ms 24184 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back

struct dsu {
    vector<int> parent, rank;
    int size;

    dsu(int sz) {
        size = sz;
        rank.assign(size, 1);
        parent.resize(size);
        for(int i = 0; i<size; i++) parent[i] = i;
    }
    int search(int v) {
        if(v == parent[v]) return v;
        return parent[v] = search(parent[v]);
    }
    void connect(int v, int u) {
        v = search(v);
        u = search(u);
        if(v == u) return;
        if(rank[v]>=rank[u]) parent[u] = v;
        else parent[v] = u;
        if(rank[v] == rank[u]) rank[v]++;
        return;
    }
};

void build(std::vector<std::vector<int>> b);
int construct(std::vector<std::vector<int>> p) {
	int n = p.size();
	bool ctr = 1;
    vector<vector<int>> b(n);
    for(int i = 0; i<n; i++) b[i].resize(n, 0);
    
    vector<int> a[n];
    dsu d = dsu(n);
    for(int i = 0; i<n; i++) {
        for(int j = 0; j<n; j++) {
            if(p[i][j]) d.connect(i, j);
        }
    }
    for(int i = 0; i<n; i++) {
        a[d.search(i)].pb(i);
    }
    for(int i = 0; i<n; i++) {
        if(a[i].size()<=1) continue;
        int pth = p[a[i][0]][a[i][1]];
        for(int ii:a[i]) {
            for(int j:a[i]) {
                if(ii == j) continue;
                if(p[ii][j] != pth) ctr = 0;
            }
        }
        for(int ii = 1; ii<a[i].size(); ii++) {
            b[a[i][ii]][a[i][ii-1]] = b[a[i][ii-1]][a[i][ii]] = 1;
        }
        if(pth == 2) b[a[i][0]][a[i].back()] = b[a[i].back()][a[i][0]] = 1;
        if(pth == 2 && a[i].size() == 2) ctr = 0;
    }
	if(ctr) build(b);
	return ctr;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:56:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |         for(int ii = 1; ii<a[i].size(); ii++) {
      |                         ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 10 ms 1116 KB Output is correct
7 Correct 121 ms 22096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 10 ms 1116 KB Output is correct
7 Correct 121 ms 22096 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 5 ms 1104 KB Output is correct
13 Correct 118 ms 22032 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 68 ms 12056 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 42 ms 5724 KB Output is correct
21 Correct 124 ms 23972 KB Output is correct
22 Correct 116 ms 24144 KB Output is correct
23 Correct 171 ms 24144 KB Output is correct
24 Correct 118 ms 24184 KB Output is correct
25 Correct 56 ms 14164 KB Output is correct
26 Correct 77 ms 14164 KB Output is correct
27 Correct 181 ms 23924 KB Output is correct
28 Correct 122 ms 24148 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 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 5 ms 1116 KB Output is correct
9 Correct 139 ms 22052 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 9 ms 1108 KB Output is correct
13 Correct 180 ms 22036 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 76 ms 12296 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 32 ms 5716 KB Output is correct
22 Correct 137 ms 23944 KB Output is correct
23 Correct 139 ms 24068 KB Output is correct
24 Correct 164 ms 23980 KB Output is correct
25 Correct 59 ms 14200 KB Output is correct
26 Correct 66 ms 14244 KB Output is correct
27 Correct 146 ms 23976 KB Output is correct
28 Correct 160 ms 24144 KB Output is correct
29 Correct 70 ms 14164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 30 ms 6236 KB Output is correct
5 Correct 184 ms 24060 KB Output is correct
6 Correct 121 ms 23944 KB Output is correct
7 Correct 170 ms 24144 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 30 ms 6232 KB Output is correct
10 Correct 119 ms 23944 KB Output is correct
11 Correct 164 ms 23940 KB Output is correct
12 Correct 134 ms 24072 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Incorrect 0 ms 348 KB Answer gives possible 0 while actual possible 1
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 10 ms 1116 KB Output is correct
7 Correct 121 ms 22096 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 5 ms 1104 KB Output is correct
13 Correct 118 ms 22032 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 68 ms 12056 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 42 ms 5724 KB Output is correct
21 Correct 124 ms 23972 KB Output is correct
22 Correct 116 ms 24144 KB Output is correct
23 Correct 171 ms 24144 KB Output is correct
24 Correct 118 ms 24184 KB Output is correct
25 Correct 56 ms 14164 KB Output is correct
26 Correct 77 ms 14164 KB Output is correct
27 Correct 181 ms 23924 KB Output is correct
28 Correct 122 ms 24148 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 0 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 5 ms 1116 KB Output is correct
37 Correct 139 ms 22052 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 9 ms 1108 KB Output is correct
41 Correct 180 ms 22036 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 3 ms 860 KB Output is correct
45 Correct 76 ms 12296 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 1 ms 344 KB Output is correct
49 Correct 32 ms 5716 KB Output is correct
50 Correct 137 ms 23944 KB Output is correct
51 Correct 139 ms 24068 KB Output is correct
52 Correct 164 ms 23980 KB Output is correct
53 Correct 59 ms 14200 KB Output is correct
54 Correct 66 ms 14244 KB Output is correct
55 Correct 146 ms 23976 KB Output is correct
56 Correct 160 ms 24144 KB Output is correct
57 Correct 70 ms 14164 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 3 ms 928 KB Output is correct
61 Correct 64 ms 14088 KB Output is correct
62 Correct 1 ms 344 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 0 ms 596 KB Output is correct
65 Incorrect 13 ms 3716 KB Answer gives possible 0 while actual possible 1
66 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 10 ms 1116 KB Output is correct
7 Correct 121 ms 22096 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 5 ms 1104 KB Output is correct
13 Correct 118 ms 22032 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 68 ms 12056 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 42 ms 5724 KB Output is correct
21 Correct 124 ms 23972 KB Output is correct
22 Correct 116 ms 24144 KB Output is correct
23 Correct 171 ms 24144 KB Output is correct
24 Correct 118 ms 24184 KB Output is correct
25 Correct 56 ms 14164 KB Output is correct
26 Correct 77 ms 14164 KB Output is correct
27 Correct 181 ms 23924 KB Output is correct
28 Correct 122 ms 24148 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 0 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 5 ms 1116 KB Output is correct
37 Correct 139 ms 22052 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 9 ms 1108 KB Output is correct
41 Correct 180 ms 22036 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 3 ms 860 KB Output is correct
45 Correct 76 ms 12296 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 1 ms 344 KB Output is correct
49 Correct 32 ms 5716 KB Output is correct
50 Correct 137 ms 23944 KB Output is correct
51 Correct 139 ms 24068 KB Output is correct
52 Correct 164 ms 23980 KB Output is correct
53 Correct 59 ms 14200 KB Output is correct
54 Correct 66 ms 14244 KB Output is correct
55 Correct 146 ms 23976 KB Output is correct
56 Correct 160 ms 24144 KB Output is correct
57 Correct 70 ms 14164 KB Output is correct
58 Correct 0 ms 344 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 30 ms 6236 KB Output is correct
62 Correct 184 ms 24060 KB Output is correct
63 Correct 121 ms 23944 KB Output is correct
64 Correct 170 ms 24144 KB Output is correct
65 Correct 1 ms 344 KB Output is correct
66 Correct 30 ms 6232 KB Output is correct
67 Correct 119 ms 23944 KB Output is correct
68 Correct 164 ms 23940 KB Output is correct
69 Correct 134 ms 24072 KB Output is correct
70 Correct 0 ms 348 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Incorrect 0 ms 348 KB Answer gives possible 0 while actual possible 1
73 Halted 0 ms 0 KB -