답안 #316759

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
316759 2020-10-27T21:24:44 Z jainbot27 슈퍼트리 잇기 (IOI20_supertrees) C++17
100 / 100
304 ms 30164 KB
#include <bits/stdc++.h>
#ifndef ACMX 
#include "supertrees.h"
#endif
using namespace std;

#define f first
#define s second
#define pb push_back
#define ar array
#define all(x) x.begin(), x.end()
#define siz(x) (int)x.size()

#define FOR(x, y, z) for(int x = (y); x < (z); x++)
#define ROF(x, z, y) for(int x = (y-1); x >= (z); x--)
#define F0R(x, z) FOR(x, 0, z)
#define R0F(x, z) ROF(x, 0, z)
#define trav(x, y) for(auto&x:y)

using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;

template<class T> inline bool ckmin(T&a, T b) {return b < a ? a = b, 1 : 0;}
template<class T> inline bool ckmax(T&a, T b) {return b > a ? a = b, 1 : 0;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const char nl = '\n';
const int mxN = 1001;
const int MOD = 1e9 + 7;
const long long infLL = 1e18;

struct dsu{
    vi par, sz; 
    void init(int n) {
        par.resize(n);
        sz.resize(n, 1);
        F0R(i, n) par[i] = i;
    }
    int find(int x){
        return par[x] = (par[x] == x ? x : find(par[x]));
    }
    void comb(int a, int b){
        a = find(a), b = find(b);
        if(a != b){
            if(sz[a] < sz[b]) swap(a, b);
            sz[a] += sz[b];
            par[b] = a;
        }
    }
};

vector<vi> res;
dsu o, t;
vpii q[4];
vector<vi> tot;
/*
void build(vector<vi> res){
    int n = siz(res);
    F0R(i, n){
        F0R(j, n){
            cout << res[i][j];
        }
        cout << nl;
    }
}*/
int construct(vector<vi> g){
    int n = siz(g);
    res = g;
    F0R(i, n) fill(all(res[i]), 0);
    F0R(i, n){
        F0R(j, n){
            q[g[i][j]].pb({i, j});
        }
    }
    o.init(n);
    tot.resize(n);
    if(siz(q[3])) return 0;
    trav(x, q[1]){
        o.comb(x.f, x.s);
    }
    F0R(i, n){
        if(o.find(i)!=i)
            res[o.find(i)][i]=res[i][o.find(i)]=1;
        //res[i][i]=1;
    }

    t.init(n);
    trav(x, q[2]){
        t.comb(o.find(x.f), o.find(x.s));
    }
    F0R(i, n){
        F0R(j, n){
            if(o.find(i)==o.find(j)){
                if(g[i][j]==2 || g[i][j] == 0) return 0;
            }
        }
    }
    F0R(i, n){
        if(t.sz[t.find(i)] == 1) continue;
        if(t.sz[t.find(i)] == 2) return 0;
        tot[t.find(i)].pb(i);
    }
    F0R(i, n){
        if(siz(tot[i])){
            res[tot[i][0]][tot[i].back()]=res[tot[i].back()][tot[i][0]]=1;
            F0R(j, siz(tot[i])-1){
                o.comb(tot[i][j], tot[i][j+1]);
                res[tot[i][j]][tot[i][j+1]]=
                res[tot[i][j+1]][tot[i][j]]=1;
            }
        }
    }
    trav(x, q[0]){
        if(o.find(x.f)==o.find(x.s)) return 0;
    }
    build(res);
    return 1;
}
/*
int main(){
    int N; cin >> N;
    vector<vi> g(N, vi(N));
    F0R(i, N){
        F0R(j, N){
            cin >> g[i][j];
        }
    }
    construct(g);
}
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 12 ms 1532 KB Output is correct
7 Correct 277 ms 30164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 12 ms 1532 KB Output is correct
7 Correct 277 ms 30164 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 11 ms 1536 KB Output is correct
13 Correct 282 ms 30036 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 6 ms 1404 KB Output is correct
17 Correct 135 ms 20160 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 67 ms 7792 KB Output is correct
21 Correct 304 ms 30068 KB Output is correct
22 Correct 266 ms 30036 KB Output is correct
23 Correct 285 ms 30024 KB Output is correct
24 Correct 260 ms 30032 KB Output is correct
25 Correct 119 ms 21384 KB Output is correct
26 Correct 115 ms 20460 KB Output is correct
27 Correct 281 ms 30028 KB Output is correct
28 Correct 257 ms 30032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 11 ms 1536 KB Output is correct
9 Correct 254 ms 29904 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 12 ms 1664 KB Output is correct
13 Correct 279 ms 29912 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 6 ms 1348 KB Output is correct
17 Correct 137 ms 20188 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 0 ms 256 KB Output is correct
21 Correct 67 ms 7796 KB Output is correct
22 Correct 265 ms 29940 KB Output is correct
23 Correct 265 ms 30040 KB Output is correct
24 Correct 277 ms 30020 KB Output is correct
25 Correct 116 ms 20584 KB Output is correct
26 Correct 121 ms 21384 KB Output is correct
27 Correct 259 ms 30016 KB Output is correct
28 Correct 275 ms 30028 KB Output is correct
29 Correct 121 ms 20584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 67 ms 7792 KB Output is correct
5 Correct 271 ms 29940 KB Output is correct
6 Correct 270 ms 30036 KB Output is correct
7 Correct 284 ms 30028 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 67 ms 7920 KB Output is correct
10 Correct 270 ms 29940 KB Output is correct
11 Correct 262 ms 30040 KB Output is correct
12 Correct 278 ms 30024 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 70 ms 7792 KB Output is correct
17 Correct 267 ms 30164 KB Output is correct
18 Correct 275 ms 30068 KB Output is correct
19 Correct 273 ms 30044 KB Output is correct
20 Correct 266 ms 30036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 12 ms 1532 KB Output is correct
7 Correct 277 ms 30164 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 11 ms 1536 KB Output is correct
13 Correct 282 ms 30036 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 6 ms 1404 KB Output is correct
17 Correct 135 ms 20160 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 67 ms 7792 KB Output is correct
21 Correct 304 ms 30068 KB Output is correct
22 Correct 266 ms 30036 KB Output is correct
23 Correct 285 ms 30024 KB Output is correct
24 Correct 260 ms 30032 KB Output is correct
25 Correct 119 ms 21384 KB Output is correct
26 Correct 115 ms 20460 KB Output is correct
27 Correct 281 ms 30028 KB Output is correct
28 Correct 257 ms 30032 KB Output is correct
29 Correct 0 ms 256 KB Output is correct
30 Correct 0 ms 256 KB Output is correct
31 Correct 0 ms 256 KB Output is correct
32 Correct 1 ms 256 KB Output is correct
33 Correct 0 ms 256 KB Output is correct
34 Correct 1 ms 256 KB Output is correct
35 Correct 0 ms 256 KB Output is correct
36 Correct 11 ms 1536 KB Output is correct
37 Correct 254 ms 29904 KB Output is correct
38 Correct 1 ms 256 KB Output is correct
39 Correct 0 ms 256 KB Output is correct
40 Correct 12 ms 1664 KB Output is correct
41 Correct 279 ms 29912 KB Output is correct
42 Correct 1 ms 256 KB Output is correct
43 Correct 1 ms 256 KB Output is correct
44 Correct 6 ms 1348 KB Output is correct
45 Correct 137 ms 20188 KB Output is correct
46 Correct 1 ms 256 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 0 ms 256 KB Output is correct
49 Correct 67 ms 7796 KB Output is correct
50 Correct 265 ms 29940 KB Output is correct
51 Correct 265 ms 30040 KB Output is correct
52 Correct 277 ms 30020 KB Output is correct
53 Correct 116 ms 20584 KB Output is correct
54 Correct 121 ms 21384 KB Output is correct
55 Correct 259 ms 30016 KB Output is correct
56 Correct 275 ms 30028 KB Output is correct
57 Correct 121 ms 20584 KB Output is correct
58 Correct 0 ms 256 KB Output is correct
59 Correct 0 ms 256 KB Output is correct
60 Correct 6 ms 1280 KB Output is correct
61 Correct 140 ms 20524 KB Output is correct
62 Correct 0 ms 256 KB Output is correct
63 Correct 0 ms 256 KB Output is correct
64 Correct 1 ms 256 KB Output is correct
65 Correct 67 ms 7792 KB Output is correct
66 Correct 127 ms 21384 KB Output is correct
67 Correct 123 ms 21384 KB Output is correct
68 Correct 128 ms 20864 KB Output is correct
69 Correct 123 ms 20584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 12 ms 1532 KB Output is correct
7 Correct 277 ms 30164 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 11 ms 1536 KB Output is correct
13 Correct 282 ms 30036 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 6 ms 1404 KB Output is correct
17 Correct 135 ms 20160 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 67 ms 7792 KB Output is correct
21 Correct 304 ms 30068 KB Output is correct
22 Correct 266 ms 30036 KB Output is correct
23 Correct 285 ms 30024 KB Output is correct
24 Correct 260 ms 30032 KB Output is correct
25 Correct 119 ms 21384 KB Output is correct
26 Correct 115 ms 20460 KB Output is correct
27 Correct 281 ms 30028 KB Output is correct
28 Correct 257 ms 30032 KB Output is correct
29 Correct 0 ms 256 KB Output is correct
30 Correct 0 ms 256 KB Output is correct
31 Correct 0 ms 256 KB Output is correct
32 Correct 1 ms 256 KB Output is correct
33 Correct 0 ms 256 KB Output is correct
34 Correct 1 ms 256 KB Output is correct
35 Correct 0 ms 256 KB Output is correct
36 Correct 11 ms 1536 KB Output is correct
37 Correct 254 ms 29904 KB Output is correct
38 Correct 1 ms 256 KB Output is correct
39 Correct 0 ms 256 KB Output is correct
40 Correct 12 ms 1664 KB Output is correct
41 Correct 279 ms 29912 KB Output is correct
42 Correct 1 ms 256 KB Output is correct
43 Correct 1 ms 256 KB Output is correct
44 Correct 6 ms 1348 KB Output is correct
45 Correct 137 ms 20188 KB Output is correct
46 Correct 1 ms 256 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 0 ms 256 KB Output is correct
49 Correct 67 ms 7796 KB Output is correct
50 Correct 265 ms 29940 KB Output is correct
51 Correct 265 ms 30040 KB Output is correct
52 Correct 277 ms 30020 KB Output is correct
53 Correct 116 ms 20584 KB Output is correct
54 Correct 121 ms 21384 KB Output is correct
55 Correct 259 ms 30016 KB Output is correct
56 Correct 275 ms 30028 KB Output is correct
57 Correct 121 ms 20584 KB Output is correct
58 Correct 1 ms 256 KB Output is correct
59 Correct 0 ms 256 KB Output is correct
60 Correct 0 ms 256 KB Output is correct
61 Correct 67 ms 7792 KB Output is correct
62 Correct 271 ms 29940 KB Output is correct
63 Correct 270 ms 30036 KB Output is correct
64 Correct 284 ms 30028 KB Output is correct
65 Correct 1 ms 256 KB Output is correct
66 Correct 67 ms 7920 KB Output is correct
67 Correct 270 ms 29940 KB Output is correct
68 Correct 262 ms 30040 KB Output is correct
69 Correct 278 ms 30024 KB Output is correct
70 Correct 0 ms 256 KB Output is correct
71 Correct 0 ms 256 KB Output is correct
72 Correct 1 ms 256 KB Output is correct
73 Correct 70 ms 7792 KB Output is correct
74 Correct 267 ms 30164 KB Output is correct
75 Correct 275 ms 30068 KB Output is correct
76 Correct 273 ms 30044 KB Output is correct
77 Correct 266 ms 30036 KB Output is correct
78 Correct 0 ms 256 KB Output is correct
79 Correct 0 ms 256 KB Output is correct
80 Correct 6 ms 1280 KB Output is correct
81 Correct 140 ms 20524 KB Output is correct
82 Correct 0 ms 256 KB Output is correct
83 Correct 0 ms 256 KB Output is correct
84 Correct 1 ms 256 KB Output is correct
85 Correct 67 ms 7792 KB Output is correct
86 Correct 127 ms 21384 KB Output is correct
87 Correct 123 ms 21384 KB Output is correct
88 Correct 128 ms 20864 KB Output is correct
89 Correct 123 ms 20584 KB Output is correct
90 Correct 0 ms 256 KB Output is correct
91 Correct 0 ms 256 KB Output is correct
92 Correct 6 ms 1408 KB Output is correct
93 Correct 128 ms 20164 KB Output is correct
94 Correct 1 ms 256 KB Output is correct
95 Correct 1 ms 256 KB Output is correct
96 Correct 0 ms 256 KB Output is correct
97 Correct 29 ms 5492 KB Output is correct
98 Correct 118 ms 21352 KB Output is correct
99 Correct 118 ms 21384 KB Output is correct
100 Correct 115 ms 20720 KB Output is correct
101 Correct 113 ms 20512 KB Output is correct
102 Correct 129 ms 20584 KB Output is correct
103 Correct 134 ms 20180 KB Output is correct
104 Correct 130 ms 20180 KB Output is correct
105 Correct 129 ms 20188 KB Output is correct