답안 #976163

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
976163 2024-05-06T08:51:33 Z efedmrlr 슈퍼트리 잇기 (IOI20_supertrees) C++17
96 / 100
158 ms 22300 KB
// #pragma GCC optimize("O3,Ofast,unroll-loops")
// #pragma GCC target("avx2,bmi,popcnt")
#include <bits/stdc++.h>
#include "supertrees.h"


#define lli long long int
#define ld long double
#define REP(i, n) for(int i = 0; (i) < (n); (i)++)
#define all(x) x.begin(), x.end();
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define MP make_pair

using namespace std;

void fastio() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const int N = 1e5 + 5;
const int INF = 1e9 + 500;
const int MOD = 1e9 + 7;

struct DSU {
    vector<int> p, sz, typ;
    int n;
    void make_set(int x) {
        p[x] = x;
        sz[x] = 1;
    }
    void init(int nn) {
        n = nn;
        p.assign(n + 3, 0);
        sz.assign(n + 3, 0);
        typ.assign(n + 3, 0);
        for(int i = 0; i < n; i++) {
            make_set(i);
        }
    }
    int find_set(int x) {
        return (x == p[x]) ? x : p[x] = find_set(p[x]);
    }
    bool union_set(int x, int y) {
        x = find_set(x); y = find_set(y);
        if(x == y) return 0;
        if(sz[x] < sz[y]) swap(x, y);
        sz[x] += sz[y];
        p[y] = x;
        return 1;
    }
};

int construct(std::vector<std::vector<int>> p) {
	int n = (int)p.size();
	vector<vector<int> > ans(n, vector<int>(n, 0));
    DSU ds;
    ds.init(n);

    // check zero
    bool f = 1;
    for(int i = 0; i < n; i++) {
        for(int j = i + 1; j < n; j++) {
            if(p[i][j]) {
                ds.union_set(i, j);
            }
        }
    }
    for(int i = 0; i < n; i++) {
        for(int j = i + 1; j < n; j++) {
            if(!p[i][j] && ds.find_set(i) == ds.find_set(j)) {
                f = 0;
            }
        }
    }
    if(!f) return 0;
    // cerr << "zort" << endl;
    ds.init(n);
    vector<int> reps;
    for(int i = 0; i < n; i++) {
        for(int j = i + 1; j < n; j++) {
            if(p[i][j] == 1) {
                ds.union_set(i, j);
            }
        }
    }
    vector<vector<int> > comp(n, vector<int>());
    for(int i = 0; i < n; i++) {
        if(ds.find_set(i) == i) reps.pb(i);
        comp[ds.find_set(i)].pb(i);
    }
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < (int)comp[i].size() - 1; j++) {
            ans[comp[i][j]][comp[i][j + 1]] = 1;
            ans[comp[i][j + 1]][comp[i][j]] = 1;
        }
    }
    DSU ds2;
    ds2.init(n);
    // for(auto c : reps) {
    //     cout << c << " ";
    // }
    // cout << "\n\n";
    for(int i = 0; i < reps.size(); i++) {
        for(int j = i + 1; j < reps.size(); j++) {
            if(p[reps[i]][reps[j]] == 2) {
                ds2.union_set(reps[i], reps[j]);
            } 
        }
    }
    comp.assign(n, vector<int>());
    for(int i = 0; i < n; i++) {
        comp[ds2.find_set(i)].pb(i);
    }
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < (int)comp[i].size() - 1; j++) {
            ans[comp[i][j]][comp[i][j + 1]] = 1;
            ans[comp[i][j + 1]][comp[i][j]] = 1;
        }
        if(comp[i].size() > 1) {
            ans[comp[i].back()][comp[i][0]] = 1;
            ans[comp[i][0]][comp[i].back()] = 1;
        }
        if(comp[i].size() == 2) {
            f = 0;
        }
    }

    if(!f) return 0;

    build(ans);

	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:105:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  105 |     for(int i = 0; i < reps.size(); i++) {
      |                    ~~^~~~~~~~~~~~~
supertrees.cpp:106:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |         for(int j = i + 1; j < reps.size(); j++) {
      |                            ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 6 ms 1116 KB Output is correct
7 Correct 148 ms 22024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 6 ms 1116 KB Output is correct
7 Correct 148 ms 22024 KB Output is correct
8 Correct 1 ms 348 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 6 ms 1116 KB Output is correct
13 Correct 146 ms 22152 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 71 ms 12116 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 38 ms 5812 KB Output is correct
21 Correct 148 ms 22028 KB Output is correct
22 Correct 145 ms 22100 KB Output is correct
23 Correct 155 ms 22092 KB Output is correct
24 Correct 150 ms 22100 KB Output is correct
25 Correct 70 ms 12036 KB Output is correct
26 Correct 65 ms 12036 KB Output is correct
27 Correct 152 ms 22268 KB Output is correct
28 Correct 146 ms 22244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 6 ms 1324 KB Output is correct
9 Correct 152 ms 22300 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 6 ms 1268 KB Output is correct
13 Correct 150 ms 22260 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 70 ms 12060 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 38 ms 5724 KB Output is correct
22 Correct 148 ms 22104 KB Output is correct
23 Correct 149 ms 22212 KB Output is correct
24 Correct 153 ms 22100 KB Output is correct
25 Correct 62 ms 12304 KB Output is correct
26 Correct 64 ms 12116 KB Output is correct
27 Correct 146 ms 22060 KB Output is correct
28 Correct 157 ms 22300 KB Output is correct
29 Correct 64 ms 12112 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 37 ms 5720 KB Output is correct
5 Correct 157 ms 22100 KB Output is correct
6 Correct 144 ms 22096 KB Output is correct
7 Correct 158 ms 22020 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 37 ms 5716 KB Output is correct
10 Correct 147 ms 22024 KB Output is correct
11 Correct 146 ms 22096 KB Output is correct
12 Correct 151 ms 22096 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 37 ms 5724 KB Output is correct
17 Correct 148 ms 22040 KB Output is correct
18 Correct 146 ms 22040 KB Output is correct
19 Correct 145 ms 22040 KB Output is correct
20 Correct 154 ms 22028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 6 ms 1116 KB Output is correct
7 Correct 148 ms 22024 KB Output is correct
8 Correct 1 ms 348 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 6 ms 1116 KB Output is correct
13 Correct 146 ms 22152 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 71 ms 12116 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 38 ms 5812 KB Output is correct
21 Correct 148 ms 22028 KB Output is correct
22 Correct 145 ms 22100 KB Output is correct
23 Correct 155 ms 22092 KB Output is correct
24 Correct 150 ms 22100 KB Output is correct
25 Correct 70 ms 12036 KB Output is correct
26 Correct 65 ms 12036 KB Output is correct
27 Correct 152 ms 22268 KB Output is correct
28 Correct 146 ms 22244 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 6 ms 1324 KB Output is correct
37 Correct 152 ms 22300 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 6 ms 1268 KB Output is correct
41 Correct 150 ms 22260 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 70 ms 12060 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 344 KB Output is correct
48 Correct 1 ms 344 KB Output is correct
49 Correct 38 ms 5724 KB Output is correct
50 Correct 148 ms 22104 KB Output is correct
51 Correct 149 ms 22212 KB Output is correct
52 Correct 153 ms 22100 KB Output is correct
53 Correct 62 ms 12304 KB Output is correct
54 Correct 64 ms 12116 KB Output is correct
55 Correct 146 ms 22060 KB Output is correct
56 Correct 157 ms 22300 KB Output is correct
57 Correct 64 ms 12112 KB Output is correct
58 Correct 1 ms 344 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 3 ms 860 KB Output is correct
61 Correct 68 ms 12040 KB Output is correct
62 Correct 0 ms 348 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 1 ms 348 KB Output is correct
65 Correct 37 ms 5944 KB Output is correct
66 Correct 69 ms 14196 KB Output is correct
67 Correct 63 ms 14160 KB Output is correct
68 Correct 62 ms 14160 KB Output is correct
69 Correct 63 ms 14088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 6 ms 1116 KB Output is correct
7 Correct 148 ms 22024 KB Output is correct
8 Correct 1 ms 348 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 6 ms 1116 KB Output is correct
13 Correct 146 ms 22152 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 71 ms 12116 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 38 ms 5812 KB Output is correct
21 Correct 148 ms 22028 KB Output is correct
22 Correct 145 ms 22100 KB Output is correct
23 Correct 155 ms 22092 KB Output is correct
24 Correct 150 ms 22100 KB Output is correct
25 Correct 70 ms 12036 KB Output is correct
26 Correct 65 ms 12036 KB Output is correct
27 Correct 152 ms 22268 KB Output is correct
28 Correct 146 ms 22244 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 6 ms 1324 KB Output is correct
37 Correct 152 ms 22300 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 6 ms 1268 KB Output is correct
41 Correct 150 ms 22260 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 70 ms 12060 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 344 KB Output is correct
48 Correct 1 ms 344 KB Output is correct
49 Correct 38 ms 5724 KB Output is correct
50 Correct 148 ms 22104 KB Output is correct
51 Correct 149 ms 22212 KB Output is correct
52 Correct 153 ms 22100 KB Output is correct
53 Correct 62 ms 12304 KB Output is correct
54 Correct 64 ms 12116 KB Output is correct
55 Correct 146 ms 22060 KB Output is correct
56 Correct 157 ms 22300 KB Output is correct
57 Correct 64 ms 12112 KB Output is correct
58 Correct 0 ms 344 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 37 ms 5720 KB Output is correct
62 Correct 157 ms 22100 KB Output is correct
63 Correct 144 ms 22096 KB Output is correct
64 Correct 158 ms 22020 KB Output is correct
65 Correct 0 ms 344 KB Output is correct
66 Correct 37 ms 5716 KB Output is correct
67 Correct 147 ms 22024 KB Output is correct
68 Correct 146 ms 22096 KB Output is correct
69 Correct 151 ms 22096 KB Output is correct
70 Correct 0 ms 344 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 0 ms 348 KB Output is correct
73 Correct 37 ms 5724 KB Output is correct
74 Correct 148 ms 22040 KB Output is correct
75 Correct 146 ms 22040 KB Output is correct
76 Correct 145 ms 22040 KB Output is correct
77 Correct 154 ms 22028 KB Output is correct
78 Correct 1 ms 344 KB Output is correct
79 Correct 0 ms 348 KB Output is correct
80 Correct 3 ms 860 KB Output is correct
81 Correct 68 ms 12040 KB Output is correct
82 Correct 0 ms 348 KB Output is correct
83 Correct 0 ms 348 KB Output is correct
84 Correct 1 ms 348 KB Output is correct
85 Correct 37 ms 5944 KB Output is correct
86 Correct 69 ms 14196 KB Output is correct
87 Correct 63 ms 14160 KB Output is correct
88 Correct 62 ms 14160 KB Output is correct
89 Correct 63 ms 14088 KB Output is correct
90 Correct 1 ms 344 KB Output is correct
91 Correct 0 ms 348 KB Output is correct
92 Correct 3 ms 956 KB Output is correct
93 Correct 69 ms 14348 KB Output is correct
94 Incorrect 0 ms 344 KB Answer gives possible 1 while actual possible 0
95 Halted 0 ms 0 KB -