Submission #613890

# Submission time Handle Problem Language Result Execution time Memory
613890 2022-07-30T12:28:24 Z alirezasamimi100 Connecting Supertrees (IOI20_supertrees) C++17
100 / 100
221 ms 23508 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back

const int N = 1e3 + 10;

int n,P[N];
vector<int> vec[N],cy[N];

int gp(int x){
    return P[x]!=-1?P[x]=gp(P[x]):x;
}

void uni(int v, int u){
    v=gp(v);
    u=gp(u);
    if(v==u) return;
    P[u]=v;
}

int construct(vector<vector<int>> p) {
    memset(P,-1,sizeof P);
    n = p.size();
    vector<vector<int>> ans(n,vector<int>(n,0));
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            if(p[i][j]==1) uni(i,j);
            if(p[i][j]==3) return 0;
        }
    }
    for(int i=0; i<n; i++) vec[gp(i)].pb(i);
    memset(P,-1,sizeof P);
    for(int i=0; i<n; i++){
        for(int j : vec[i]){
            if(j!=i) ans[i][j]=ans[j][i]=1;
            for(int k : vec[i]) if(p[j][k]!=1) return 0;
        }
        for(int j=0; j<n; j++){
            if(i==j) continue;
            bool f=0,g=0;
            for(int x : vec[i]){
                for(int y : vec[j]){
                    if(p[x][y]==2) f=1;
                    if(p[x][y]==0) g=1;
                }
            }
            if(f && g) return 0;
            if(f) uni(i,j);
        }
    }
    for(int i=0; i<n; i++) if(!vec[i].empty()){
        cy[gp(i)].pb(i);
    }
    for(int i=0; i<n; i++){
        for(int a : cy[i]){
            for(int b : cy[i]){
                if(a==b) continue;
                for(int x : vec[a]){
                    for(int y : vec[b]){
                        if(p[x][y]!=2) return 0;
                    }
                }
            }
        }
        if((int)cy[i].size()==2) return 0;
        if((int)cy[i].size()<3) continue;
        int ls = i;
        for(int j : cy[i]){
            if(j==i) continue;
            ans[ls][j]=ans[j][ls]=1;
            ls=j;
        }
        ans[ls][i]=ans[i][ls]=1;
    }
    build(ans);
    return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 10 ms 1236 KB Output is correct
7 Correct 196 ms 23156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 10 ms 1236 KB Output is correct
7 Correct 196 ms 23156 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 352 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 8 ms 1256 KB Output is correct
13 Correct 183 ms 23240 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 360 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 81 ms 13220 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 352 KB Output is correct
20 Correct 47 ms 6200 KB Output is correct
21 Correct 191 ms 23140 KB Output is correct
22 Correct 186 ms 23196 KB Output is correct
23 Correct 192 ms 23344 KB Output is correct
24 Correct 212 ms 23236 KB Output is correct
25 Correct 74 ms 13260 KB Output is correct
26 Correct 87 ms 13332 KB Output is correct
27 Correct 188 ms 23196 KB Output is correct
28 Correct 192 ms 23284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 352 KB Output is correct
5 Correct 0 ms 352 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 8 ms 1256 KB Output is correct
9 Correct 195 ms 23312 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 11 ms 1232 KB Output is correct
13 Correct 187 ms 23380 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 5 ms 852 KB Output is correct
17 Correct 99 ms 13320 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 47 ms 6268 KB Output is correct
22 Correct 196 ms 23320 KB Output is correct
23 Correct 184 ms 23388 KB Output is correct
24 Correct 200 ms 23508 KB Output is correct
25 Correct 78 ms 14120 KB Output is correct
26 Correct 74 ms 14132 KB Output is correct
27 Correct 188 ms 23416 KB Output is correct
28 Correct 196 ms 23352 KB Output is correct
29 Correct 72 ms 14124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 356 KB Output is correct
4 Correct 47 ms 6208 KB Output is correct
5 Correct 181 ms 23348 KB Output is correct
6 Correct 190 ms 23356 KB Output is correct
7 Correct 188 ms 23388 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 49 ms 6220 KB Output is correct
10 Correct 204 ms 23344 KB Output is correct
11 Correct 221 ms 23352 KB Output is correct
12 Correct 199 ms 23424 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 48 ms 6312 KB Output is correct
17 Correct 186 ms 23372 KB Output is correct
18 Correct 203 ms 23324 KB Output is correct
19 Correct 185 ms 23344 KB Output is correct
20 Correct 192 ms 23416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 10 ms 1236 KB Output is correct
7 Correct 196 ms 23156 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 352 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 8 ms 1256 KB Output is correct
13 Correct 183 ms 23240 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 360 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 81 ms 13220 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 352 KB Output is correct
20 Correct 47 ms 6200 KB Output is correct
21 Correct 191 ms 23140 KB Output is correct
22 Correct 186 ms 23196 KB Output is correct
23 Correct 192 ms 23344 KB Output is correct
24 Correct 212 ms 23236 KB Output is correct
25 Correct 74 ms 13260 KB Output is correct
26 Correct 87 ms 13332 KB Output is correct
27 Correct 188 ms 23196 KB Output is correct
28 Correct 192 ms 23284 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 352 KB Output is correct
33 Correct 0 ms 352 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 8 ms 1256 KB Output is correct
37 Correct 195 ms 23312 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 11 ms 1232 KB Output is correct
41 Correct 187 ms 23380 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 5 ms 852 KB Output is correct
45 Correct 99 ms 13320 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 47 ms 6268 KB Output is correct
50 Correct 196 ms 23320 KB Output is correct
51 Correct 184 ms 23388 KB Output is correct
52 Correct 200 ms 23508 KB Output is correct
53 Correct 78 ms 14120 KB Output is correct
54 Correct 74 ms 14132 KB Output is correct
55 Correct 188 ms 23416 KB Output is correct
56 Correct 196 ms 23352 KB Output is correct
57 Correct 72 ms 14124 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 0 ms 340 KB Output is correct
60 Correct 4 ms 852 KB Output is correct
61 Correct 80 ms 14120 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 47 ms 6300 KB Output is correct
66 Correct 76 ms 14116 KB Output is correct
67 Correct 73 ms 14116 KB Output is correct
68 Correct 79 ms 14128 KB Output is correct
69 Correct 76 ms 14120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 10 ms 1236 KB Output is correct
7 Correct 196 ms 23156 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 352 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 8 ms 1256 KB Output is correct
13 Correct 183 ms 23240 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 360 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 81 ms 13220 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 352 KB Output is correct
20 Correct 47 ms 6200 KB Output is correct
21 Correct 191 ms 23140 KB Output is correct
22 Correct 186 ms 23196 KB Output is correct
23 Correct 192 ms 23344 KB Output is correct
24 Correct 212 ms 23236 KB Output is correct
25 Correct 74 ms 13260 KB Output is correct
26 Correct 87 ms 13332 KB Output is correct
27 Correct 188 ms 23196 KB Output is correct
28 Correct 192 ms 23284 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 352 KB Output is correct
33 Correct 0 ms 352 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 8 ms 1256 KB Output is correct
37 Correct 195 ms 23312 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 11 ms 1232 KB Output is correct
41 Correct 187 ms 23380 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 5 ms 852 KB Output is correct
45 Correct 99 ms 13320 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 47 ms 6268 KB Output is correct
50 Correct 196 ms 23320 KB Output is correct
51 Correct 184 ms 23388 KB Output is correct
52 Correct 200 ms 23508 KB Output is correct
53 Correct 78 ms 14120 KB Output is correct
54 Correct 74 ms 14132 KB Output is correct
55 Correct 188 ms 23416 KB Output is correct
56 Correct 196 ms 23352 KB Output is correct
57 Correct 72 ms 14124 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 1 ms 356 KB Output is correct
61 Correct 47 ms 6208 KB Output is correct
62 Correct 181 ms 23348 KB Output is correct
63 Correct 190 ms 23356 KB Output is correct
64 Correct 188 ms 23388 KB Output is correct
65 Correct 0 ms 340 KB Output is correct
66 Correct 49 ms 6220 KB Output is correct
67 Correct 204 ms 23344 KB Output is correct
68 Correct 221 ms 23352 KB Output is correct
69 Correct 199 ms 23424 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 0 ms 340 KB Output is correct
73 Correct 48 ms 6312 KB Output is correct
74 Correct 186 ms 23372 KB Output is correct
75 Correct 203 ms 23324 KB Output is correct
76 Correct 185 ms 23344 KB Output is correct
77 Correct 192 ms 23416 KB Output is correct
78 Correct 1 ms 340 KB Output is correct
79 Correct 0 ms 340 KB Output is correct
80 Correct 4 ms 852 KB Output is correct
81 Correct 80 ms 14120 KB Output is correct
82 Correct 1 ms 340 KB Output is correct
83 Correct 1 ms 340 KB Output is correct
84 Correct 1 ms 340 KB Output is correct
85 Correct 47 ms 6300 KB Output is correct
86 Correct 76 ms 14116 KB Output is correct
87 Correct 73 ms 14116 KB Output is correct
88 Correct 79 ms 14128 KB Output is correct
89 Correct 76 ms 14120 KB Output is correct
90 Correct 1 ms 352 KB Output is correct
91 Correct 1 ms 348 KB Output is correct
92 Correct 4 ms 852 KB Output is correct
93 Correct 73 ms 14128 KB Output is correct
94 Correct 0 ms 340 KB Output is correct
95 Correct 1 ms 340 KB Output is correct
96 Correct 1 ms 356 KB Output is correct
97 Correct 19 ms 3788 KB Output is correct
98 Correct 71 ms 14116 KB Output is correct
99 Correct 80 ms 14120 KB Output is correct
100 Correct 77 ms 14120 KB Output is correct
101 Correct 74 ms 14040 KB Output is correct
102 Correct 74 ms 14156 KB Output is correct
103 Correct 72 ms 14052 KB Output is correct
104 Correct 72 ms 14048 KB Output is correct
105 Correct 77 ms 14120 KB Output is correct