답안 #334111

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
334111 2020-12-08T10:50:29 Z balbit 슈퍼트리 잇기 (IOI20_supertrees) C++14
100 / 100
297 ms 28284 KB
#include <bits/stdc++.h>
#ifndef BALBIT
#include "supertrees.h"
#endif // BALBIT
using namespace std;

#define ll long long
#define pii pair<int, int>
#define f first
#define s second

#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)(x.size())
#define pb push_back

#ifdef BALBIT
#define bug(...) cerr<<"#"<<__LINE__<<": "<<#__VA_ARGS__<<": ", _do(__VA_ARGS__)
template<typename T> void _do(T && x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T && x, S && ...y){cerr<<x<<", "; _do(y...);}
#define IOS()
#else
#define IOS() ios::sync_with_stdio(0), cin.tie(0)
#define bug(...)
#define endl '\n'
#endif // BALBIT

#define REP(i,n) for (int i = 0; i<n;++i)
#define REP1(i,n) for (int i = 1; i<=n;++i)

const int maxn = 1005;


int n;
vector<vector<int> > g;
vector<vector<int> > ans;
int c1[maxn], c2[maxn];
vector<int> vec1[maxn];
int colorhead[maxn];
bool seen[maxn];

void dfs1(int v, int c) {
    seen[v] = 1; c1[v] = c; vec1[c].pb(v);
    REP(u,n) {
        if (!seen[u] && g[v][u] == 1) {
            dfs1(u,c);
        }
    }
}

set<int> poscol;

void dfs2(int v, int c) {
    seen[v] = 1;
    poscol.insert(c1[v]);
    c2[v] = c;
    REP(u,n) {
        if (!seen[u] && (g[v][u] == 2 || g[v][u] == 1)) {
            dfs2(u,c);
        }
    }
}

inline void mark(int a, int b) {
    ans[a][b] = ans[b][a] = 1;
}

#ifdef BALBIT
void build(vector<vector<int> > x) {
    REP(i,n) REP(j,n) {
        if (x[i][j]) bug(i,j);
//        cout<<x[i][j]<<" \n"[j==n-1];
    }
}
#endif // BALBIT

int construct(vector<vector<int>> _p) {
    g = _p;
	n = g.size();
	ans = vector<vector<int> > (n, vector<int> (n,0));
    REP(i,n) REP(j,n) {
        if (g[i][j] == 3) {
            return 0;
        }
    }
    int NC = 0;
    REP(i,n) {
        if (!seen[i]) {
            colorhead[NC] = i;
            dfs1(i,NC++);
        }
    }
    // check if they are cliques
    REP(i,n) REP(j,n) {
        if (i != j && c1[i] == c1[j]) {
            if (g[i][j] != 1) return 0;
        }
    }
    REP(i,NC) {
        REP(j, SZ(vec1[i])) {
            if (j) mark(vec1[i][j], vec1[i][j-1]);
        }
    }
    memset(seen, 0, sizeof seen);
    int NC2 = 0;
    REP(i,n) {
        if (!seen[i]) {
            dfs2(i, NC2);
            vector<int> tmp;
            for (int x : poscol) {
                tmp.pb(x);
            }
            poscol.clear();
            if (SZ(tmp) == 2) {
                return 0;
            }
            if (SZ(tmp) > 1)
                REP(i, SZ(tmp)) {
                    int j = i == SZ(tmp)-1? 0 : i+1;
                    mark(colorhead[tmp[i]],colorhead[tmp[j]]);
                }
            ++NC2;
        }
    }

    REP(i,n) REP(j,n) {
        if (i != j && c2[i] == c2[j]) {
            if (g[i][j] != 1 && g[i][j] != 2) return 0;
        }
    }

    build(ans);
	return 1;
}

#ifdef BALBIT
signed main(){
//    bug(1,2);
    construct({{1, 1, 2, 2}, {1, 1, 2, 2}, {2, 2, 1, 2}, {2, 2, 2, 1}});
}
#endif
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 11 ms 1516 KB Output is correct
7 Correct 256 ms 28140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 11 ms 1516 KB Output is correct
7 Correct 256 ms 28140 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 13 ms 1516 KB Output is correct
13 Correct 256 ms 28140 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 5 ms 1132 KB Output is correct
17 Correct 125 ms 18156 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 66 ms 7404 KB Output is correct
21 Correct 268 ms 28032 KB Output is correct
22 Correct 260 ms 28140 KB Output is correct
23 Correct 272 ms 28140 KB Output is correct
24 Correct 257 ms 28012 KB Output is correct
25 Correct 106 ms 18156 KB Output is correct
26 Correct 106 ms 18160 KB Output is correct
27 Correct 271 ms 28140 KB Output is correct
28 Correct 268 ms 28140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 404 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 13 ms 1516 KB Output is correct
9 Correct 259 ms 28012 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 11 ms 1516 KB Output is correct
13 Correct 262 ms 28140 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 7 ms 1132 KB Output is correct
17 Correct 117 ms 18284 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 65 ms 7404 KB Output is correct
22 Correct 262 ms 28268 KB Output is correct
23 Correct 260 ms 28140 KB Output is correct
24 Correct 269 ms 28268 KB Output is correct
25 Correct 107 ms 18284 KB Output is correct
26 Correct 110 ms 18156 KB Output is correct
27 Correct 260 ms 28012 KB Output is correct
28 Correct 269 ms 28140 KB Output is correct
29 Correct 107 ms 18156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 70 ms 7532 KB Output is correct
5 Correct 260 ms 28012 KB Output is correct
6 Correct 258 ms 28012 KB Output is correct
7 Correct 297 ms 28012 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 65 ms 7404 KB Output is correct
10 Correct 263 ms 28012 KB Output is correct
11 Correct 260 ms 28012 KB Output is correct
12 Correct 265 ms 28140 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 65 ms 7404 KB Output is correct
17 Correct 264 ms 28284 KB Output is correct
18 Correct 264 ms 28140 KB Output is correct
19 Correct 260 ms 28012 KB Output is correct
20 Correct 258 ms 28032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 11 ms 1516 KB Output is correct
7 Correct 256 ms 28140 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 13 ms 1516 KB Output is correct
13 Correct 256 ms 28140 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 5 ms 1132 KB Output is correct
17 Correct 125 ms 18156 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 66 ms 7404 KB Output is correct
21 Correct 268 ms 28032 KB Output is correct
22 Correct 260 ms 28140 KB Output is correct
23 Correct 272 ms 28140 KB Output is correct
24 Correct 257 ms 28012 KB Output is correct
25 Correct 106 ms 18156 KB Output is correct
26 Correct 106 ms 18160 KB Output is correct
27 Correct 271 ms 28140 KB Output is correct
28 Correct 268 ms 28140 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 404 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 492 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 13 ms 1516 KB Output is correct
37 Correct 259 ms 28012 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 11 ms 1516 KB Output is correct
41 Correct 262 ms 28140 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 7 ms 1132 KB Output is correct
45 Correct 117 ms 18284 KB Output is correct
46 Correct 1 ms 364 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 65 ms 7404 KB Output is correct
50 Correct 262 ms 28268 KB Output is correct
51 Correct 260 ms 28140 KB Output is correct
52 Correct 269 ms 28268 KB Output is correct
53 Correct 107 ms 18284 KB Output is correct
54 Correct 110 ms 18156 KB Output is correct
55 Correct 260 ms 28012 KB Output is correct
56 Correct 269 ms 28140 KB Output is correct
57 Correct 107 ms 18156 KB Output is correct
58 Correct 1 ms 364 KB Output is correct
59 Correct 1 ms 364 KB Output is correct
60 Correct 5 ms 1132 KB Output is correct
61 Correct 119 ms 18284 KB Output is correct
62 Correct 1 ms 492 KB Output is correct
63 Correct 1 ms 364 KB Output is correct
64 Correct 1 ms 364 KB Output is correct
65 Correct 66 ms 7404 KB Output is correct
66 Correct 111 ms 18156 KB Output is correct
67 Correct 107 ms 18156 KB Output is correct
68 Correct 110 ms 18156 KB Output is correct
69 Correct 115 ms 18176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 11 ms 1516 KB Output is correct
7 Correct 256 ms 28140 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 13 ms 1516 KB Output is correct
13 Correct 256 ms 28140 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 5 ms 1132 KB Output is correct
17 Correct 125 ms 18156 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 66 ms 7404 KB Output is correct
21 Correct 268 ms 28032 KB Output is correct
22 Correct 260 ms 28140 KB Output is correct
23 Correct 272 ms 28140 KB Output is correct
24 Correct 257 ms 28012 KB Output is correct
25 Correct 106 ms 18156 KB Output is correct
26 Correct 106 ms 18160 KB Output is correct
27 Correct 271 ms 28140 KB Output is correct
28 Correct 268 ms 28140 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 404 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 492 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 13 ms 1516 KB Output is correct
37 Correct 259 ms 28012 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 11 ms 1516 KB Output is correct
41 Correct 262 ms 28140 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 7 ms 1132 KB Output is correct
45 Correct 117 ms 18284 KB Output is correct
46 Correct 1 ms 364 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 65 ms 7404 KB Output is correct
50 Correct 262 ms 28268 KB Output is correct
51 Correct 260 ms 28140 KB Output is correct
52 Correct 269 ms 28268 KB Output is correct
53 Correct 107 ms 18284 KB Output is correct
54 Correct 110 ms 18156 KB Output is correct
55 Correct 260 ms 28012 KB Output is correct
56 Correct 269 ms 28140 KB Output is correct
57 Correct 107 ms 18156 KB Output is correct
58 Correct 1 ms 364 KB Output is correct
59 Correct 1 ms 364 KB Output is correct
60 Correct 1 ms 364 KB Output is correct
61 Correct 70 ms 7532 KB Output is correct
62 Correct 260 ms 28012 KB Output is correct
63 Correct 258 ms 28012 KB Output is correct
64 Correct 297 ms 28012 KB Output is correct
65 Correct 1 ms 364 KB Output is correct
66 Correct 65 ms 7404 KB Output is correct
67 Correct 263 ms 28012 KB Output is correct
68 Correct 260 ms 28012 KB Output is correct
69 Correct 265 ms 28140 KB Output is correct
70 Correct 1 ms 364 KB Output is correct
71 Correct 1 ms 364 KB Output is correct
72 Correct 1 ms 364 KB Output is correct
73 Correct 65 ms 7404 KB Output is correct
74 Correct 264 ms 28284 KB Output is correct
75 Correct 264 ms 28140 KB Output is correct
76 Correct 260 ms 28012 KB Output is correct
77 Correct 258 ms 28032 KB Output is correct
78 Correct 1 ms 364 KB Output is correct
79 Correct 1 ms 364 KB Output is correct
80 Correct 5 ms 1132 KB Output is correct
81 Correct 119 ms 18284 KB Output is correct
82 Correct 1 ms 492 KB Output is correct
83 Correct 1 ms 364 KB Output is correct
84 Correct 1 ms 364 KB Output is correct
85 Correct 66 ms 7404 KB Output is correct
86 Correct 111 ms 18156 KB Output is correct
87 Correct 107 ms 18156 KB Output is correct
88 Correct 110 ms 18156 KB Output is correct
89 Correct 115 ms 18176 KB Output is correct
90 Correct 1 ms 364 KB Output is correct
91 Correct 1 ms 364 KB Output is correct
92 Correct 5 ms 1132 KB Output is correct
93 Correct 107 ms 18156 KB Output is correct
94 Correct 1 ms 364 KB Output is correct
95 Correct 1 ms 364 KB Output is correct
96 Correct 1 ms 364 KB Output is correct
97 Correct 26 ms 4844 KB Output is correct
98 Correct 106 ms 18156 KB Output is correct
99 Correct 104 ms 18176 KB Output is correct
100 Correct 105 ms 18412 KB Output is correct
101 Correct 103 ms 18156 KB Output is correct
102 Correct 104 ms 18156 KB Output is correct
103 Correct 107 ms 18176 KB Output is correct
104 Correct 107 ms 18156 KB Output is correct
105 Correct 109 ms 18156 KB Output is correct