답안 #526225

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
526225 2022-02-14T01:33:36 Z pokmui9909 슈퍼트리 잇기 (IOI20_supertrees) C++17
100 / 100
259 ms 24060 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

class UnionFind{
public:
	UnionFind(ll S){
		p.resize(S + 5, -1);
	}
	ll Find(ll n){
		if (p[n] < 0) return n;
		else return p[n] = Find(p[n]);
	}
	void Union(ll a, ll b){
		a = Find(a), b = Find(b);
		if (a == b) return;
        p[a] += p[b];
		p[b] = a;
    }
	bool Same(ll a, ll b) { return Find(a) == Find(b); }
	ll Size(ll n) { return -p[Find(n)]; }
    bool Root(ll n) {return n == Find(n);}
private:
	vector<ll> p;
};
ll N; 
vector<ll> A;

int construct(std::vector<std::vector<int>> P) {
	N = P.size();
    vector<vector<int>> T(N, vector<int>(N));
    auto add_edge = [&](ll u, ll v) -> void{
        T[u][v] = T[v][u] = 1;
    };
    UnionFind S1(N), S2(N);
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            if(P[i][j] == 3){
                return 0;
            }
            if(j >= i || P[i][j] == 0) continue;
            S1.Union(i, j);
            if(P[i][j] == 1){
                S2.Union(i, j);
            }
        }
    }
    for(int i = 0; i < N; i++){
        if(!S2.Root(i)){
            add_edge(S2.Find(i), i);
        }
    }
    for(int i = 0; i < N; i++){
        for(int j = i + 1; j < N; j++){
            if(S2.Same(i, j) && P[i][j] != 1){
                return 0;
            } else if(S1.Same(i, j) && P[i][j] != 2 && P[i][j] != 1){
                return 0;
            }
        }
    }
    for(int i = 0; i < N; i++){
        if(!S1.Root(i)) continue;
        A.clear();
        for(int j = 0; j < N; j++){
            if(S1.Same(i, j) && S2.Root(j)){
                A.push_back(j);
            }
        }
        if(A.size() == 2) return 0;
        if(A.size() == 1) continue;
        for(int j = 0; j < A.size(); j++){
            add_edge(A[j], A[(j == A.size() - 1 ? 0 : j + 1)]);
        }
    }
    build(T);
    return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:73:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |         for(int j = 0; j < A.size(); j++){
      |                        ~~^~~~~~~~~~
supertrees.cpp:74:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |             add_edge(A[j], A[(j == A.size() - 1 ? 0 : j + 1)]);
      |                               ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 7 ms 1204 KB Output is correct
7 Correct 169 ms 23928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 7 ms 1204 KB Output is correct
7 Correct 169 ms 23928 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 8 ms 1204 KB Output is correct
13 Correct 163 ms 23988 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 5 ms 844 KB Output is correct
17 Correct 92 ms 14076 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 0 ms 288 KB Output is correct
20 Correct 41 ms 6180 KB Output is correct
21 Correct 166 ms 23996 KB Output is correct
22 Correct 210 ms 23916 KB Output is correct
23 Correct 185 ms 23976 KB Output is correct
24 Correct 181 ms 23932 KB Output is correct
25 Correct 68 ms 13992 KB Output is correct
26 Correct 68 ms 14020 KB Output is correct
27 Correct 189 ms 23928 KB Output is correct
28 Correct 161 ms 23912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 288 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 292 KB Output is correct
5 Correct 1 ms 288 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 292 KB Output is correct
8 Correct 9 ms 1224 KB Output is correct
9 Correct 197 ms 24044 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 8 ms 1192 KB Output is correct
13 Correct 164 ms 23916 KB Output is correct
14 Correct 1 ms 324 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 4 ms 816 KB Output is correct
17 Correct 82 ms 14060 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 288 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 41 ms 6252 KB Output is correct
22 Correct 170 ms 23964 KB Output is correct
23 Correct 187 ms 24004 KB Output is correct
24 Correct 182 ms 24012 KB Output is correct
25 Correct 96 ms 14076 KB Output is correct
26 Correct 71 ms 14060 KB Output is correct
27 Correct 175 ms 23924 KB Output is correct
28 Correct 186 ms 23916 KB Output is correct
29 Correct 88 ms 13980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 292 KB Output is correct
4 Correct 44 ms 6192 KB Output is correct
5 Correct 165 ms 23912 KB Output is correct
6 Correct 166 ms 23964 KB Output is correct
7 Correct 198 ms 23912 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 44 ms 6248 KB Output is correct
10 Correct 181 ms 24024 KB Output is correct
11 Correct 198 ms 24016 KB Output is correct
12 Correct 189 ms 24004 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 64 ms 6184 KB Output is correct
17 Correct 172 ms 23964 KB Output is correct
18 Correct 183 ms 24060 KB Output is correct
19 Correct 259 ms 24008 KB Output is correct
20 Correct 249 ms 23984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 7 ms 1204 KB Output is correct
7 Correct 169 ms 23928 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 8 ms 1204 KB Output is correct
13 Correct 163 ms 23988 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 5 ms 844 KB Output is correct
17 Correct 92 ms 14076 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 0 ms 288 KB Output is correct
20 Correct 41 ms 6180 KB Output is correct
21 Correct 166 ms 23996 KB Output is correct
22 Correct 210 ms 23916 KB Output is correct
23 Correct 185 ms 23976 KB Output is correct
24 Correct 181 ms 23932 KB Output is correct
25 Correct 68 ms 13992 KB Output is correct
26 Correct 68 ms 14020 KB Output is correct
27 Correct 189 ms 23928 KB Output is correct
28 Correct 161 ms 23912 KB Output is correct
29 Correct 0 ms 288 KB Output is correct
30 Correct 1 ms 296 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 292 KB Output is correct
33 Correct 1 ms 288 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 0 ms 292 KB Output is correct
36 Correct 9 ms 1224 KB Output is correct
37 Correct 197 ms 24044 KB Output is correct
38 Correct 0 ms 204 KB Output is correct
39 Correct 0 ms 204 KB Output is correct
40 Correct 8 ms 1192 KB Output is correct
41 Correct 164 ms 23916 KB Output is correct
42 Correct 1 ms 324 KB Output is correct
43 Correct 0 ms 204 KB Output is correct
44 Correct 4 ms 816 KB Output is correct
45 Correct 82 ms 14060 KB Output is correct
46 Correct 0 ms 204 KB Output is correct
47 Correct 0 ms 288 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 41 ms 6252 KB Output is correct
50 Correct 170 ms 23964 KB Output is correct
51 Correct 187 ms 24004 KB Output is correct
52 Correct 182 ms 24012 KB Output is correct
53 Correct 96 ms 14076 KB Output is correct
54 Correct 71 ms 14060 KB Output is correct
55 Correct 175 ms 23924 KB Output is correct
56 Correct 186 ms 23916 KB Output is correct
57 Correct 88 ms 13980 KB Output is correct
58 Correct 1 ms 288 KB Output is correct
59 Correct 1 ms 204 KB Output is correct
60 Correct 4 ms 784 KB Output is correct
61 Correct 99 ms 14060 KB Output is correct
62 Correct 1 ms 292 KB Output is correct
63 Correct 1 ms 288 KB Output is correct
64 Correct 1 ms 204 KB Output is correct
65 Correct 57 ms 6184 KB Output is correct
66 Correct 94 ms 14060 KB Output is correct
67 Correct 83 ms 14056 KB Output is correct
68 Correct 76 ms 14100 KB Output is correct
69 Correct 84 ms 14100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 7 ms 1204 KB Output is correct
7 Correct 169 ms 23928 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 8 ms 1204 KB Output is correct
13 Correct 163 ms 23988 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 5 ms 844 KB Output is correct
17 Correct 92 ms 14076 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 0 ms 288 KB Output is correct
20 Correct 41 ms 6180 KB Output is correct
21 Correct 166 ms 23996 KB Output is correct
22 Correct 210 ms 23916 KB Output is correct
23 Correct 185 ms 23976 KB Output is correct
24 Correct 181 ms 23932 KB Output is correct
25 Correct 68 ms 13992 KB Output is correct
26 Correct 68 ms 14020 KB Output is correct
27 Correct 189 ms 23928 KB Output is correct
28 Correct 161 ms 23912 KB Output is correct
29 Correct 0 ms 288 KB Output is correct
30 Correct 1 ms 296 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 292 KB Output is correct
33 Correct 1 ms 288 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 0 ms 292 KB Output is correct
36 Correct 9 ms 1224 KB Output is correct
37 Correct 197 ms 24044 KB Output is correct
38 Correct 0 ms 204 KB Output is correct
39 Correct 0 ms 204 KB Output is correct
40 Correct 8 ms 1192 KB Output is correct
41 Correct 164 ms 23916 KB Output is correct
42 Correct 1 ms 324 KB Output is correct
43 Correct 0 ms 204 KB Output is correct
44 Correct 4 ms 816 KB Output is correct
45 Correct 82 ms 14060 KB Output is correct
46 Correct 0 ms 204 KB Output is correct
47 Correct 0 ms 288 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 41 ms 6252 KB Output is correct
50 Correct 170 ms 23964 KB Output is correct
51 Correct 187 ms 24004 KB Output is correct
52 Correct 182 ms 24012 KB Output is correct
53 Correct 96 ms 14076 KB Output is correct
54 Correct 71 ms 14060 KB Output is correct
55 Correct 175 ms 23924 KB Output is correct
56 Correct 186 ms 23916 KB Output is correct
57 Correct 88 ms 13980 KB Output is correct
58 Correct 1 ms 204 KB Output is correct
59 Correct 0 ms 204 KB Output is correct
60 Correct 0 ms 292 KB Output is correct
61 Correct 44 ms 6192 KB Output is correct
62 Correct 165 ms 23912 KB Output is correct
63 Correct 166 ms 23964 KB Output is correct
64 Correct 198 ms 23912 KB Output is correct
65 Correct 1 ms 204 KB Output is correct
66 Correct 44 ms 6248 KB Output is correct
67 Correct 181 ms 24024 KB Output is correct
68 Correct 198 ms 24016 KB Output is correct
69 Correct 189 ms 24004 KB Output is correct
70 Correct 1 ms 204 KB Output is correct
71 Correct 1 ms 204 KB Output is correct
72 Correct 1 ms 204 KB Output is correct
73 Correct 64 ms 6184 KB Output is correct
74 Correct 172 ms 23964 KB Output is correct
75 Correct 183 ms 24060 KB Output is correct
76 Correct 259 ms 24008 KB Output is correct
77 Correct 249 ms 23984 KB Output is correct
78 Correct 1 ms 288 KB Output is correct
79 Correct 1 ms 204 KB Output is correct
80 Correct 4 ms 784 KB Output is correct
81 Correct 99 ms 14060 KB Output is correct
82 Correct 1 ms 292 KB Output is correct
83 Correct 1 ms 288 KB Output is correct
84 Correct 1 ms 204 KB Output is correct
85 Correct 57 ms 6184 KB Output is correct
86 Correct 94 ms 14060 KB Output is correct
87 Correct 83 ms 14056 KB Output is correct
88 Correct 76 ms 14100 KB Output is correct
89 Correct 84 ms 14100 KB Output is correct
90 Correct 1 ms 204 KB Output is correct
91 Correct 1 ms 204 KB Output is correct
92 Correct 5 ms 812 KB Output is correct
93 Correct 87 ms 14060 KB Output is correct
94 Correct 1 ms 204 KB Output is correct
95 Correct 1 ms 204 KB Output is correct
96 Correct 0 ms 204 KB Output is correct
97 Correct 18 ms 3680 KB Output is correct
98 Correct 87 ms 14056 KB Output is correct
99 Correct 76 ms 13992 KB Output is correct
100 Correct 79 ms 13980 KB Output is correct
101 Correct 74 ms 14072 KB Output is correct
102 Correct 68 ms 14060 KB Output is correct
103 Correct 84 ms 14076 KB Output is correct
104 Correct 71 ms 14060 KB Output is correct
105 Correct 99 ms 14056 KB Output is correct