답안 #430290

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
430290 2021-06-16T12:41:57 Z TryMax 슈퍼트리 잇기 (IOI20_supertrees) C++17
100 / 100
276 ms 24132 KB
#include "supertrees.h"
#ifdef LOCAL
    #include "grader.cpp"
#endif // LOCAL
#include <bits/stdc++.h>

#define pb push_back

using namespace std;

const int N = 1e5 + 10;

int was[N], was1[N], sz[N], pr[N];

int find_pr(int u){
    if(pr[u] == u)
        return u;
    return pr[u] = find_pr(pr[u]);
}

void union_sets(int a, int b){
    a = find_pr(a);
    b = find_pr(b);
    if(a == b)
        return;
    if(sz[a] > sz[b])
        swap(a, b);
    pr[a] = b;
    sz[b] += sz[a];
}

int construct(vector<vector<int>> p) {
	int n = p.size();
	vector<vector<int>> ans;
	ans.resize(n);
    bool f = true;
	for(int i = 0; i < n; ++i){
        ans[i].resize(n), sz[i] = 1, pr[i] = i;
        f &= (p[i][i] == 1);
	}
    vector<int> top;
    for(int i = 0; i < n; ++i){
        if(was[i])
            continue;
        top.pb(i);
        was[i] = 1;
        for(int j = 0; j < n; ++j)
            if(p[i][j] == 1 && was[j] == 0)
                was[j] = 1, ans[i][j] = 1, union_sets(i, j);
    }
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < n; ++j)
            if(find_pr(i) == find_pr(j)){
                f &= (p[i][j] == 1);
                p[i][j] = 2;
            }
//    for(int i = 0; i < n; ++i)
//        cout << find_pr(i) << " ";
//    cout << endl;
    for(int i = 0; i < top.size(); ++i){
        if(was1[top[i]])
            continue;
        vector<int> now;
        now.pb(top[i]);
        was1[top[i]] = 1;
        for(int j = 0; j < top.size(); ++j)
            if(was1[top[j]] == 0 && p[top[i]][top[j]] == 2 && find_pr(top[i]) != find_pr(top[j]))
                now.pb(top[j]), was1[top[j]] = 1, union_sets(top[i], top[j]);
        for(int j = 0; j < now.size() - 1; ++j)
            ans[now[j]][now[j + 1]] = 1;
        if(now.size() == 2)
            f = false;
        if(now.size() > 1)
            ans[now.back()][now[0]] = 1;
    }

//    for(int i = 0; i < n; ++i)
//        cout << find_pr(i) << " ";
//    cout << endl;
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < n; ++j)
            if(find_pr(i) == find_pr(j)){
                f &= (p[i][j] == 2);
                p[i][j] = 0;
            }
//    for(int i = 0; i < n; ++i){
//        for(int j = 0; j < n; ++j)
//            cout << p[i][j] << " ";
//        cout << endl;
//    }
//    cout << f << endl;
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < n; ++j){
            f &= (p[i][j] == 0);
            ans[i][j] = ans[j][i] = (ans[i][j] | ans[j][i]);
        }
    if(f){
        build(ans);
        return 1;
    }else
        return 0;
}
/*
4
1 1 2 2
1 1 2 2
2 2 1 2
2 2 2 1

1
0 1 0 0
1 0 1 1
0 1 0 1
0 1 1 0

2
1 0
0 1

1
0 0
0 0

2
1 3
3 1

0
*/

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:60:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |     for(int i = 0; i < top.size(); ++i){
      |                    ~~^~~~~~~~~~~~
supertrees.cpp:66:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |         for(int j = 0; j < top.size(); ++j)
      |                        ~~^~~~~~~~~~~~
supertrees.cpp:69:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |         for(int j = 0; j < now.size() - 1; ++j)
      |                        ~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 240 KB Output is correct
2 Correct 1 ms 260 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 12 ms 1100 KB Output is correct
7 Correct 238 ms 22032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 240 KB Output is correct
2 Correct 1 ms 260 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 12 ms 1100 KB Output is correct
7 Correct 238 ms 22032 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 10 ms 1100 KB Output is correct
13 Correct 256 ms 22156 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 5 ms 720 KB Output is correct
17 Correct 122 ms 12164 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 59 ms 5768 KB Output is correct
21 Correct 251 ms 22016 KB Output is correct
22 Correct 239 ms 22012 KB Output is correct
23 Correct 275 ms 21992 KB Output is correct
24 Correct 253 ms 21992 KB Output is correct
25 Correct 118 ms 12152 KB Output is correct
26 Correct 110 ms 12048 KB Output is correct
27 Correct 257 ms 21964 KB Output is correct
28 Correct 234 ms 22020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 224 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 296 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 10 ms 1264 KB Output is correct
9 Correct 247 ms 23948 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 10 ms 1208 KB Output is correct
13 Correct 248 ms 23940 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 8 ms 844 KB Output is correct
17 Correct 114 ms 14208 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 59 ms 6208 KB Output is correct
22 Correct 252 ms 23932 KB Output is correct
23 Correct 233 ms 24004 KB Output is correct
24 Correct 250 ms 24132 KB Output is correct
25 Correct 106 ms 14076 KB Output is correct
26 Correct 106 ms 14076 KB Output is correct
27 Correct 231 ms 23972 KB Output is correct
28 Correct 250 ms 24052 KB Output is correct
29 Correct 105 ms 14068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 60 ms 5768 KB Output is correct
5 Correct 255 ms 21948 KB Output is correct
6 Correct 253 ms 22084 KB Output is correct
7 Correct 252 ms 21956 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 58 ms 5764 KB Output is correct
10 Correct 242 ms 22036 KB Output is correct
11 Correct 241 ms 22032 KB Output is correct
12 Correct 242 ms 22032 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 61 ms 5764 KB Output is correct
17 Correct 238 ms 21972 KB Output is correct
18 Correct 241 ms 22028 KB Output is correct
19 Correct 276 ms 22212 KB Output is correct
20 Correct 254 ms 22028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 240 KB Output is correct
2 Correct 1 ms 260 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 12 ms 1100 KB Output is correct
7 Correct 238 ms 22032 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 10 ms 1100 KB Output is correct
13 Correct 256 ms 22156 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 5 ms 720 KB Output is correct
17 Correct 122 ms 12164 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 59 ms 5768 KB Output is correct
21 Correct 251 ms 22016 KB Output is correct
22 Correct 239 ms 22012 KB Output is correct
23 Correct 275 ms 21992 KB Output is correct
24 Correct 253 ms 21992 KB Output is correct
25 Correct 118 ms 12152 KB Output is correct
26 Correct 110 ms 12048 KB Output is correct
27 Correct 257 ms 21964 KB Output is correct
28 Correct 234 ms 22020 KB Output is correct
29 Correct 1 ms 224 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 296 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 10 ms 1264 KB Output is correct
37 Correct 247 ms 23948 KB Output is correct
38 Correct 1 ms 300 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 10 ms 1208 KB Output is correct
41 Correct 248 ms 23940 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 8 ms 844 KB Output is correct
45 Correct 114 ms 14208 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 59 ms 6208 KB Output is correct
50 Correct 252 ms 23932 KB Output is correct
51 Correct 233 ms 24004 KB Output is correct
52 Correct 250 ms 24132 KB Output is correct
53 Correct 106 ms 14076 KB Output is correct
54 Correct 106 ms 14076 KB Output is correct
55 Correct 231 ms 23972 KB Output is correct
56 Correct 250 ms 24052 KB Output is correct
57 Correct 105 ms 14068 KB Output is correct
58 Correct 1 ms 204 KB Output is correct
59 Correct 1 ms 204 KB Output is correct
60 Correct 6 ms 896 KB Output is correct
61 Correct 139 ms 14116 KB Output is correct
62 Correct 1 ms 204 KB Output is correct
63 Correct 1 ms 204 KB Output is correct
64 Correct 1 ms 204 KB Output is correct
65 Correct 61 ms 6268 KB Output is correct
66 Correct 107 ms 14196 KB Output is correct
67 Correct 169 ms 14104 KB Output is correct
68 Correct 120 ms 14128 KB Output is correct
69 Correct 113 ms 14076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 240 KB Output is correct
2 Correct 1 ms 260 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 12 ms 1100 KB Output is correct
7 Correct 238 ms 22032 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 10 ms 1100 KB Output is correct
13 Correct 256 ms 22156 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 5 ms 720 KB Output is correct
17 Correct 122 ms 12164 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 59 ms 5768 KB Output is correct
21 Correct 251 ms 22016 KB Output is correct
22 Correct 239 ms 22012 KB Output is correct
23 Correct 275 ms 21992 KB Output is correct
24 Correct 253 ms 21992 KB Output is correct
25 Correct 118 ms 12152 KB Output is correct
26 Correct 110 ms 12048 KB Output is correct
27 Correct 257 ms 21964 KB Output is correct
28 Correct 234 ms 22020 KB Output is correct
29 Correct 1 ms 224 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 296 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 10 ms 1264 KB Output is correct
37 Correct 247 ms 23948 KB Output is correct
38 Correct 1 ms 300 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 10 ms 1208 KB Output is correct
41 Correct 248 ms 23940 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 8 ms 844 KB Output is correct
45 Correct 114 ms 14208 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 59 ms 6208 KB Output is correct
50 Correct 252 ms 23932 KB Output is correct
51 Correct 233 ms 24004 KB Output is correct
52 Correct 250 ms 24132 KB Output is correct
53 Correct 106 ms 14076 KB Output is correct
54 Correct 106 ms 14076 KB Output is correct
55 Correct 231 ms 23972 KB Output is correct
56 Correct 250 ms 24052 KB Output is correct
57 Correct 105 ms 14068 KB Output is correct
58 Correct 1 ms 204 KB Output is correct
59 Correct 1 ms 204 KB Output is correct
60 Correct 1 ms 204 KB Output is correct
61 Correct 60 ms 5768 KB Output is correct
62 Correct 255 ms 21948 KB Output is correct
63 Correct 253 ms 22084 KB Output is correct
64 Correct 252 ms 21956 KB Output is correct
65 Correct 1 ms 204 KB Output is correct
66 Correct 58 ms 5764 KB Output is correct
67 Correct 242 ms 22036 KB Output is correct
68 Correct 241 ms 22032 KB Output is correct
69 Correct 242 ms 22032 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 61 ms 5764 KB Output is correct
74 Correct 238 ms 21972 KB Output is correct
75 Correct 241 ms 22028 KB Output is correct
76 Correct 276 ms 22212 KB Output is correct
77 Correct 254 ms 22028 KB Output is correct
78 Correct 1 ms 204 KB Output is correct
79 Correct 1 ms 204 KB Output is correct
80 Correct 6 ms 896 KB Output is correct
81 Correct 139 ms 14116 KB Output is correct
82 Correct 1 ms 204 KB Output is correct
83 Correct 1 ms 204 KB Output is correct
84 Correct 1 ms 204 KB Output is correct
85 Correct 61 ms 6268 KB Output is correct
86 Correct 107 ms 14196 KB Output is correct
87 Correct 169 ms 14104 KB Output is correct
88 Correct 120 ms 14128 KB Output is correct
89 Correct 113 ms 14076 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 844 KB Output is correct
93 Correct 120 ms 14072 KB Output is correct
94 Correct 1 ms 204 KB Output is correct
95 Correct 1 ms 204 KB Output is correct
96 Correct 1 ms 204 KB Output is correct
97 Correct 30 ms 3688 KB Output is correct
98 Correct 117 ms 14076 KB Output is correct
99 Correct 119 ms 14108 KB Output is correct
100 Correct 111 ms 14072 KB Output is correct
101 Correct 108 ms 14080 KB Output is correct
102 Correct 144 ms 14072 KB Output is correct
103 Correct 106 ms 14108 KB Output is correct
104 Correct 108 ms 14084 KB Output is correct
105 Correct 140 ms 14120 KB Output is correct