답안 #950055

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
950055 2024-03-20T04:29:29 Z irmuun 슈퍼트리 잇기 (IOI20_supertrees) C++17
100 / 100
174 ms 24292 KB
#include<bits/stdc++.h>
#include "supertrees.h"

using namespace std;

#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()

struct dsu{
    int n;
    vector<int>sz,par;
    dsu(int n):n(n){
        sz.resize(n);
        par.resize(n);
        fill(all(sz),1);
        iota(all(par),0);
    }
    int find(int x){
        if(par[x]==x) return x;
        return par[x]=find(par[x]);
    }
    void merge(int x,int y){
        x=find(x);
        y=find(y);
        if(x!=y){
            if(sz[x]<sz[y]){
                swap(x,y);
            }
            sz[x]+=sz[y];
            par[y]=x;
        }
    }
    bool same(int x,int y){
        x=find(x);
        y=find(y);
        return x==y;
    }
};

int construct(vector<vector<int>>p){
    int n=p.size();
    dsu ds(n),ds_cmp(n);
    vector<vector<int>>b(n,vector<int>(n,0));
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(p[i][j]>0){
                ds_cmp.merge(i,j);
            }
            if(p[i][j]==1){
                if(!ds.same(i,j)){
                    b[i][j]=1;
                    b[j][i]=1;
                    ds.merge(i,j);
                }
            }
        }
    }
    set<int>group[n];
    for(int i=0;i<n;i++){
        group[ds_cmp.find(i)].insert(ds.find(i));
    }
    vector<int>g[n];
    for(int i=0;i<n;i++){
        g[i]=vector<int>(all(group[i]));
        int sz=g[i].size();
        if(sz<2) continue;
        if(sz==2) return 0;
        for(int j=0;j<sz;j++){
            b[g[i][j]][g[i][(j+1)%sz]]=1;
            b[g[i][(j+1)%sz]][g[i][j]]=1;
        }
    }
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(p[i][j]!=1&&ds.same(i,j)) return 0;
            if(p[i][j]!=2&&p[i][j]!=0&&!ds.same(i,j)) return 0;
            if(p[i][j]==0&&ds_cmp.same(i,j)) return 0;
        }
    }
    build(b);
    return 1;
}
# 결과 실행 시간 메모리 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 7 ms 1388 KB Output is correct
7 Correct 150 ms 23708 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 7 ms 1388 KB Output is correct
7 Correct 150 ms 23708 KB Output is correct
8 Correct 1 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 600 KB Output is correct
12 Correct 7 ms 1424 KB Output is correct
13 Correct 150 ms 23496 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 4 ms 860 KB Output is correct
17 Correct 80 ms 13452 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 38 ms 6224 KB Output is correct
21 Correct 150 ms 23376 KB Output is correct
22 Correct 153 ms 23380 KB Output is correct
23 Correct 169 ms 23372 KB Output is correct
24 Correct 151 ms 23580 KB Output is correct
25 Correct 62 ms 13580 KB Output is correct
26 Correct 62 ms 13676 KB Output is correct
27 Correct 155 ms 23544 KB Output is correct
28 Correct 174 ms 23616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 432 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 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 7 ms 1184 KB Output is correct
9 Correct 152 ms 23556 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 7 ms 1372 KB Output is correct
13 Correct 148 ms 23456 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 5 ms 896 KB Output is correct
17 Correct 66 ms 13576 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 348 KB Output is correct
21 Correct 38 ms 6228 KB Output is correct
22 Correct 146 ms 23532 KB Output is correct
23 Correct 147 ms 23376 KB Output is correct
24 Correct 168 ms 23376 KB Output is correct
25 Correct 76 ms 13636 KB Output is correct
26 Correct 64 ms 13640 KB Output is correct
27 Correct 153 ms 23460 KB Output is correct
28 Correct 164 ms 23544 KB Output is correct
29 Correct 63 ms 13648 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 0 ms 348 KB Output is correct
4 Correct 37 ms 6236 KB Output is correct
5 Correct 157 ms 23380 KB Output is correct
6 Correct 149 ms 23376 KB Output is correct
7 Correct 152 ms 23420 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 38 ms 6396 KB Output is correct
10 Correct 160 ms 23616 KB Output is correct
11 Correct 149 ms 23380 KB Output is correct
12 Correct 154 ms 23568 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 38 ms 6264 KB Output is correct
17 Correct 152 ms 24148 KB Output is correct
18 Correct 159 ms 24188 KB Output is correct
19 Correct 152 ms 24176 KB Output is correct
20 Correct 148 ms 24292 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 7 ms 1388 KB Output is correct
7 Correct 150 ms 23708 KB Output is correct
8 Correct 1 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 600 KB Output is correct
12 Correct 7 ms 1424 KB Output is correct
13 Correct 150 ms 23496 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 4 ms 860 KB Output is correct
17 Correct 80 ms 13452 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 38 ms 6224 KB Output is correct
21 Correct 150 ms 23376 KB Output is correct
22 Correct 153 ms 23380 KB Output is correct
23 Correct 169 ms 23372 KB Output is correct
24 Correct 151 ms 23580 KB Output is correct
25 Correct 62 ms 13580 KB Output is correct
26 Correct 62 ms 13676 KB Output is correct
27 Correct 155 ms 23544 KB Output is correct
28 Correct 174 ms 23616 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 1 ms 432 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 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 7 ms 1184 KB Output is correct
37 Correct 152 ms 23556 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 7 ms 1372 KB Output is correct
41 Correct 148 ms 23456 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 5 ms 896 KB Output is correct
45 Correct 66 ms 13576 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 348 KB Output is correct
49 Correct 38 ms 6228 KB Output is correct
50 Correct 146 ms 23532 KB Output is correct
51 Correct 147 ms 23376 KB Output is correct
52 Correct 168 ms 23376 KB Output is correct
53 Correct 76 ms 13636 KB Output is correct
54 Correct 64 ms 13640 KB Output is correct
55 Correct 153 ms 23460 KB Output is correct
56 Correct 164 ms 23544 KB Output is correct
57 Correct 63 ms 13648 KB Output is correct
58 Correct 0 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 69 ms 13600 KB Output is correct
62 Correct 1 ms 348 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 1 ms 344 KB Output is correct
65 Correct 37 ms 6268 KB Output is correct
66 Correct 63 ms 14328 KB Output is correct
67 Correct 62 ms 14160 KB Output is correct
68 Correct 61 ms 14200 KB Output is correct
69 Correct 62 ms 14216 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 7 ms 1388 KB Output is correct
7 Correct 150 ms 23708 KB Output is correct
8 Correct 1 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 600 KB Output is correct
12 Correct 7 ms 1424 KB Output is correct
13 Correct 150 ms 23496 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 4 ms 860 KB Output is correct
17 Correct 80 ms 13452 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 38 ms 6224 KB Output is correct
21 Correct 150 ms 23376 KB Output is correct
22 Correct 153 ms 23380 KB Output is correct
23 Correct 169 ms 23372 KB Output is correct
24 Correct 151 ms 23580 KB Output is correct
25 Correct 62 ms 13580 KB Output is correct
26 Correct 62 ms 13676 KB Output is correct
27 Correct 155 ms 23544 KB Output is correct
28 Correct 174 ms 23616 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 1 ms 432 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 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 7 ms 1184 KB Output is correct
37 Correct 152 ms 23556 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 7 ms 1372 KB Output is correct
41 Correct 148 ms 23456 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 5 ms 896 KB Output is correct
45 Correct 66 ms 13576 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 348 KB Output is correct
49 Correct 38 ms 6228 KB Output is correct
50 Correct 146 ms 23532 KB Output is correct
51 Correct 147 ms 23376 KB Output is correct
52 Correct 168 ms 23376 KB Output is correct
53 Correct 76 ms 13636 KB Output is correct
54 Correct 64 ms 13640 KB Output is correct
55 Correct 153 ms 23460 KB Output is correct
56 Correct 164 ms 23544 KB Output is correct
57 Correct 63 ms 13648 KB Output is correct
58 Correct 0 ms 348 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 6236 KB Output is correct
62 Correct 157 ms 23380 KB Output is correct
63 Correct 149 ms 23376 KB Output is correct
64 Correct 152 ms 23420 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 38 ms 6396 KB Output is correct
67 Correct 160 ms 23616 KB Output is correct
68 Correct 149 ms 23380 KB Output is correct
69 Correct 154 ms 23568 KB Output is correct
70 Correct 0 ms 348 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 0 ms 348 KB Output is correct
73 Correct 38 ms 6264 KB Output is correct
74 Correct 152 ms 24148 KB Output is correct
75 Correct 159 ms 24188 KB Output is correct
76 Correct 152 ms 24176 KB Output is correct
77 Correct 148 ms 24292 KB Output is correct
78 Correct 0 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 69 ms 13600 KB Output is correct
82 Correct 1 ms 348 KB Output is correct
83 Correct 0 ms 348 KB Output is correct
84 Correct 1 ms 344 KB Output is correct
85 Correct 37 ms 6268 KB Output is correct
86 Correct 63 ms 14328 KB Output is correct
87 Correct 62 ms 14160 KB Output is correct
88 Correct 61 ms 14200 KB Output is correct
89 Correct 62 ms 14216 KB Output is correct
90 Correct 0 ms 344 KB Output is correct
91 Correct 1 ms 344 KB Output is correct
92 Correct 3 ms 856 KB Output is correct
93 Correct 83 ms 14196 KB Output is correct
94 Correct 1 ms 540 KB Output is correct
95 Correct 0 ms 344 KB Output is correct
96 Correct 1 ms 348 KB Output is correct
97 Correct 20 ms 3932 KB Output is correct
98 Correct 63 ms 14208 KB Output is correct
99 Correct 63 ms 14328 KB Output is correct
100 Correct 61 ms 14168 KB Output is correct
101 Correct 63 ms 14160 KB Output is correct
102 Correct 68 ms 14160 KB Output is correct
103 Correct 59 ms 14160 KB Output is correct
104 Correct 63 ms 14068 KB Output is correct
105 Correct 68 ms 14200 KB Output is correct