답안 #1031339

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1031339 2024-07-22T18:05:35 Z hotboy2703 슈퍼트리 잇기 (IOI20_supertrees) C++17
100 / 100
149 ms 24148 KB
#include "supertrees.h"
#include<bits/stdc++.h>
using namespace std;
using ll = int;
#define pll pair <ll,ll>
#define fi first
#define se second
#define MP make_pair
#define sz(a) (ll((a).size()))
#define BIT(mask,i) (((mask) >> (i))&1)
#define MASK(i) (1LL<<(i))
namespace trung{
    const ll MAXN = 1510;
    ll a[MAXN][MAXN];
    bool in[MAXN];
    ll cnt2[MAXN];
    ll n;
}
int construct(std::vector<std::vector<int>> b){
    using namespace trung;
    n=sz(b);
    for (ll i = 0;i < n;i ++)for (ll j = 0;j < n;j ++){
        if (b[i][j] == 3)return 0;
        cnt2[i] += b[i][j] == 2;
    }
    vector <vector <ll> > res(n,vector <ll> (n));
    for (ll i = 0;i < n;i ++){
        if (in[i]==0){
            queue <ll> q;
            q.push(i);
            in[i] = 1;
            vector <ll> all;
            while (!q.empty()){
                ll u = q.front();
                all.push_back(u);
                q.pop();
                for (ll j = 0;j < n;j ++){
                    if (!in[j] && b[u][j]){in[j]=1;q.push(j);}
                }
            }
            for (auto x:all)for (auto y:all)if (b[x][y]==0)return 0;
            for (auto x:all)in[x] = 0;
            vector <vector <ll> > comp;
            for (auto x:all){
                if (!in[x]){
                    in[x] = 1;
                    q.push(x);
                    vector <ll> tmp;
                    while (!q.empty()){
                        ll u = q.front();
                        tmp.push_back(u);
                        q.pop();
                        for (auto j:all){
                            if (!in[j] && b[u][j]==1){in[j]=1;q.push(j);}
                        }
                    }
                    for (auto y:tmp){
                        for (auto z:tmp){
                            if (b[y][z] != 1)return 0;
                        }
                    }
                    for (ll j = 0;j + 1 < sz(tmp);j ++){
                        res[tmp[j]][tmp[j+1]] = 1;
                        res[tmp[j+1]][tmp[j]] = 1;
                    }
                    comp.push_back(tmp);
                }
            }
            if (sz(comp) > 1){
                if (sz(comp)==2){
                    return 0;
                }
                else{
                    for (ll j = 0;j + 1 < sz(comp);j ++){
                        ll u = comp[j][0],v=comp[j+1][0];
                        res[u][v] = res[v][u] = 1;
                    }
                    ll u = comp[0][0],v=comp[sz(comp)-1][0];
                    res[u][v] = res[v][u] = 1;
                }
            }
        }
    }
    build(res);
    return 1;
}
# 결과 실행 시간 메모리 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 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 5 ms 1372 KB Output is correct
7 Correct 113 ms 24144 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 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 5 ms 1372 KB Output is correct
7 Correct 113 ms 24144 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 444 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1372 KB Output is correct
13 Correct 117 ms 24148 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 860 KB Output is correct
17 Correct 55 ms 14080 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 28 ms 6288 KB Output is correct
21 Correct 117 ms 23940 KB Output is correct
22 Correct 111 ms 24144 KB Output is correct
23 Correct 130 ms 23960 KB Output is correct
24 Correct 106 ms 24144 KB Output is correct
25 Correct 50 ms 14164 KB Output is correct
26 Correct 49 ms 14164 KB Output is correct
27 Correct 131 ms 24148 KB Output is correct
28 Correct 111 ms 24148 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 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 5 ms 1372 KB Output is correct
9 Correct 111 ms 23952 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1372 KB Output is correct
13 Correct 113 ms 24088 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 860 KB Output is correct
17 Correct 57 ms 14160 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 30 ms 6228 KB Output is correct
22 Correct 112 ms 23944 KB Output is correct
23 Correct 113 ms 24148 KB Output is correct
24 Correct 116 ms 24144 KB Output is correct
25 Correct 57 ms 14012 KB Output is correct
26 Correct 51 ms 14164 KB Output is correct
27 Correct 110 ms 24148 KB Output is correct
28 Correct 120 ms 24148 KB Output is correct
29 Correct 49 ms 14164 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 28 ms 6236 KB Output is correct
5 Correct 115 ms 24144 KB Output is correct
6 Correct 124 ms 24148 KB Output is correct
7 Correct 127 ms 24144 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 28 ms 6420 KB Output is correct
10 Correct 117 ms 24148 KB Output is correct
11 Correct 106 ms 24144 KB Output is correct
12 Correct 115 ms 24080 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 29 ms 6300 KB Output is correct
17 Correct 149 ms 23940 KB Output is correct
18 Correct 114 ms 24148 KB Output is correct
19 Correct 113 ms 23996 KB Output is correct
20 Correct 111 ms 24148 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 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 5 ms 1372 KB Output is correct
7 Correct 113 ms 24144 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 444 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1372 KB Output is correct
13 Correct 117 ms 24148 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 860 KB Output is correct
17 Correct 55 ms 14080 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 28 ms 6288 KB Output is correct
21 Correct 117 ms 23940 KB Output is correct
22 Correct 111 ms 24144 KB Output is correct
23 Correct 130 ms 23960 KB Output is correct
24 Correct 106 ms 24144 KB Output is correct
25 Correct 50 ms 14164 KB Output is correct
26 Correct 49 ms 14164 KB Output is correct
27 Correct 131 ms 24148 KB Output is correct
28 Correct 111 ms 24148 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 5 ms 1372 KB Output is correct
37 Correct 111 ms 23952 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 5 ms 1372 KB Output is correct
41 Correct 113 ms 24088 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 2 ms 860 KB Output is correct
45 Correct 57 ms 14160 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 30 ms 6228 KB Output is correct
50 Correct 112 ms 23944 KB Output is correct
51 Correct 113 ms 24148 KB Output is correct
52 Correct 116 ms 24144 KB Output is correct
53 Correct 57 ms 14012 KB Output is correct
54 Correct 51 ms 14164 KB Output is correct
55 Correct 110 ms 24148 KB Output is correct
56 Correct 120 ms 24148 KB Output is correct
57 Correct 49 ms 14164 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 3 ms 860 KB Output is correct
61 Correct 54 ms 14232 KB Output is correct
62 Correct 0 ms 348 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
65 Correct 35 ms 6208 KB Output is correct
66 Correct 50 ms 14160 KB Output is correct
67 Correct 55 ms 14232 KB Output is correct
68 Correct 49 ms 14164 KB Output is correct
69 Correct 53 ms 14164 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 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 5 ms 1372 KB Output is correct
7 Correct 113 ms 24144 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 444 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1372 KB Output is correct
13 Correct 117 ms 24148 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 860 KB Output is correct
17 Correct 55 ms 14080 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 28 ms 6288 KB Output is correct
21 Correct 117 ms 23940 KB Output is correct
22 Correct 111 ms 24144 KB Output is correct
23 Correct 130 ms 23960 KB Output is correct
24 Correct 106 ms 24144 KB Output is correct
25 Correct 50 ms 14164 KB Output is correct
26 Correct 49 ms 14164 KB Output is correct
27 Correct 131 ms 24148 KB Output is correct
28 Correct 111 ms 24148 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 5 ms 1372 KB Output is correct
37 Correct 111 ms 23952 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 5 ms 1372 KB Output is correct
41 Correct 113 ms 24088 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 2 ms 860 KB Output is correct
45 Correct 57 ms 14160 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 30 ms 6228 KB Output is correct
50 Correct 112 ms 23944 KB Output is correct
51 Correct 113 ms 24148 KB Output is correct
52 Correct 116 ms 24144 KB Output is correct
53 Correct 57 ms 14012 KB Output is correct
54 Correct 51 ms 14164 KB Output is correct
55 Correct 110 ms 24148 KB Output is correct
56 Correct 120 ms 24148 KB Output is correct
57 Correct 49 ms 14164 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 28 ms 6236 KB Output is correct
62 Correct 115 ms 24144 KB Output is correct
63 Correct 124 ms 24148 KB Output is correct
64 Correct 127 ms 24144 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 28 ms 6420 KB Output is correct
67 Correct 117 ms 24148 KB Output is correct
68 Correct 106 ms 24144 KB Output is correct
69 Correct 115 ms 24080 KB Output is correct
70 Correct 0 ms 344 KB Output is correct
71 Correct 0 ms 344 KB Output is correct
72 Correct 1 ms 348 KB Output is correct
73 Correct 29 ms 6300 KB Output is correct
74 Correct 149 ms 23940 KB Output is correct
75 Correct 114 ms 24148 KB Output is correct
76 Correct 113 ms 23996 KB Output is correct
77 Correct 111 ms 24148 KB Output is correct
78 Correct 0 ms 348 KB Output is correct
79 Correct 0 ms 348 KB Output is correct
80 Correct 3 ms 860 KB Output is correct
81 Correct 54 ms 14232 KB Output is correct
82 Correct 0 ms 348 KB Output is correct
83 Correct 0 ms 348 KB Output is correct
84 Correct 0 ms 348 KB Output is correct
85 Correct 35 ms 6208 KB Output is correct
86 Correct 50 ms 14160 KB Output is correct
87 Correct 55 ms 14232 KB Output is correct
88 Correct 49 ms 14164 KB Output is correct
89 Correct 53 ms 14164 KB Output is correct
90 Correct 0 ms 348 KB Output is correct
91 Correct 0 ms 348 KB Output is correct
92 Correct 2 ms 604 KB Output is correct
93 Correct 49 ms 10200 KB Output is correct
94 Correct 0 ms 348 KB Output is correct
95 Correct 0 ms 348 KB Output is correct
96 Correct 0 ms 360 KB Output is correct
97 Correct 17 ms 2828 KB Output is correct
98 Correct 48 ms 10128 KB Output is correct
99 Correct 47 ms 10256 KB Output is correct
100 Correct 46 ms 10188 KB Output is correct
101 Correct 51 ms 10064 KB Output is correct
102 Correct 46 ms 10068 KB Output is correct
103 Correct 52 ms 10064 KB Output is correct
104 Correct 46 ms 10124 KB Output is correct
105 Correct 52 ms 10264 KB Output is correct