Submission #343247

# Submission time Handle Problem Language Result Execution time Memory
343247 2021-01-03T15:05:49 Z bigDuck Connecting Supertrees (IOI20_supertrees) C++14
100 / 100
281 ms 28396 KB
#include "supertrees.h"
#include<bits/stdc++.h>
using namespace std;
#define INIT  ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount


vector<pii> c1;
vector<pii> c2;
vector<int> c3;
vector<vector<int> > P;
int N;
int r[1010][4];
vector<vector<int>> B;

void b1(){

for(int i=0; i<N; i++){
    if(r[i][1]==(-1)){
        r[i][1]=i;
        int mx=i;
        for(int j=0; j<N; j++){
            if( (P[mx][j]==1) && (i!=j) ){
                B[mx][j]=1;
                B[j][mx]=1;
                r[j][1]=i;
                mx=j;
            }
        }
        c1.pb({i, mx});
    }
}


}


void b2(){
    for(pii p1:c1){
        int u1=p1.ft, v1=p1.sc;
        if(r[u1][2]==(-1)){
            c2.pb({u1, u1});
            r[u1][2]=u1;
            int mx=u1;
            for(pii p2:c1){
                int u2=p2.ft, v2=p2.sc;
                if(u2==u1){continue;}

                if( (r[u2 ][2]==(-1)) && (P[mx][u2]==2)  ){
                    B[mx][u2]=1;
                    B[u2][mx]=1;
                    r[u2][2]=u1;
                    mx=u2;
                    c2.back()={v1, v2};
                }
            }
            if( (c2[c2.size()-1])==mp(u1, u1) ){
                c2.pop_back();
            }
            else{
                B[u1][mx]=1;
                B[mx][u1]=1;
            }
        }

    }
}



bool check(){

    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            if(P[i][j]==3){
                return false;
            }
            if( (r[i][1]==r[j][1]) && (P[i][j]!=1) ){
                return false;
            }
            if( (r[i][1]!=r[j][1]) && (P[i][j]==1) ){
                return false;
            }




            if( (P[i][j]==2) && ( (r[ r[i][1] ][2]!=r[ r[j][1] ][2])  || (r[i][1]==r[j][1]) ) ){
                return false;
            }
            if( (r[ r[i][1] ][2]==r[ r[j][1] ][2]) && (r[ r[i][1] ][2]!=(-1)) && (r[i][1]!=r[j][1]) && (P[i][j]!=2) ){
                return false;
            }
            if( (P[i][j]==0) && ( ( (r[r[i][1] ][2]==r[r[j][1] ][2]) ) || (r[i][1]==r[j][1] ) ) ){
                return false;
            }
            if( (P[i][j]!=0) && (   ( (r[r[i][1] ][2]==(-1)) || (r[r[i][1] ][2]!=r[r[j][1] ][2]) ) && ( r[i][1]!=r[j][1]  )  ) ){
                return false;
            }
        }
    }

    for(int i=0; i<N; i++){
        int cnt=0;
        for(int j=0; j<N; j++){
            if(P[i][j]==2){
                cnt++;
            }
        }
        if( cnt==1 ){
            return false;
        }
    }

    return true;
}


int construct(std::vector<std::vector<int>> p) {
P=p; N=P.size();
memset(r, -1, sizeof(r));

B.resize(N);
for(int i=0; i<N; i++){
    B[i].resize(N);
    for(int j=0; j<N; j++){
        B[i][j]=0;
    }
}

b1();
b2();


if(check()){
    build(B);
    return 1;
}
return 0;
}
# Verdict Execution time Memory 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 10 ms 1516 KB Output is correct
7 Correct 281 ms 26092 KB Output is correct
# Verdict Execution time Memory 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 10 ms 1516 KB Output is correct
7 Correct 281 ms 26092 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 14 ms 1388 KB Output is correct
13 Correct 270 ms 26240 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 1004 KB Output is correct
17 Correct 111 ms 16108 KB Output is correct
18 Correct 0 ms 364 KB Output is correct
19 Correct 0 ms 364 KB Output is correct
20 Correct 61 ms 6892 KB Output is correct
21 Correct 273 ms 26092 KB Output is correct
22 Correct 262 ms 26092 KB Output is correct
23 Correct 256 ms 26048 KB Output is correct
24 Correct 249 ms 26092 KB Output is correct
25 Correct 105 ms 16108 KB Output is correct
26 Correct 104 ms 16108 KB Output is correct
27 Correct 259 ms 26092 KB Output is correct
28 Correct 246 ms 26092 KB Output is correct
# Verdict Execution time Memory 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 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 10 ms 1516 KB Output is correct
9 Correct 256 ms 28140 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 10 ms 1516 KB Output is correct
13 Correct 249 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 1004 KB Output is correct
17 Correct 110 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 1 ms 364 KB Output is correct
21 Correct 74 ms 7404 KB Output is correct
22 Correct 248 ms 28012 KB Output is correct
23 Correct 250 ms 28024 KB Output is correct
24 Correct 264 ms 28140 KB Output is correct
25 Correct 108 ms 18156 KB Output is correct
26 Correct 106 ms 18156 KB Output is correct
27 Correct 261 ms 28396 KB Output is correct
28 Correct 258 ms 28012 KB Output is correct
29 Correct 111 ms 18148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 268 KB Output is correct
4 Correct 62 ms 6892 KB Output is correct
5 Correct 256 ms 26092 KB Output is correct
6 Correct 256 ms 26160 KB Output is correct
7 Correct 261 ms 26212 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 63 ms 6892 KB Output is correct
10 Correct 250 ms 26092 KB Output is correct
11 Correct 250 ms 26092 KB Output is correct
12 Correct 255 ms 26220 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 62 ms 6892 KB Output is correct
17 Correct 251 ms 26220 KB Output is correct
18 Correct 246 ms 26092 KB Output is correct
19 Correct 246 ms 26092 KB Output is correct
20 Correct 249 ms 26220 KB Output is correct
# Verdict Execution time Memory 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 10 ms 1516 KB Output is correct
7 Correct 281 ms 26092 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 14 ms 1388 KB Output is correct
13 Correct 270 ms 26240 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 1004 KB Output is correct
17 Correct 111 ms 16108 KB Output is correct
18 Correct 0 ms 364 KB Output is correct
19 Correct 0 ms 364 KB Output is correct
20 Correct 61 ms 6892 KB Output is correct
21 Correct 273 ms 26092 KB Output is correct
22 Correct 262 ms 26092 KB Output is correct
23 Correct 256 ms 26048 KB Output is correct
24 Correct 249 ms 26092 KB Output is correct
25 Correct 105 ms 16108 KB Output is correct
26 Correct 104 ms 16108 KB Output is correct
27 Correct 259 ms 26092 KB Output is correct
28 Correct 246 ms 26092 KB Output is correct
29 Correct 0 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 0 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 10 ms 1516 KB Output is correct
37 Correct 256 ms 28140 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 10 ms 1516 KB Output is correct
41 Correct 249 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 5 ms 1004 KB Output is correct
45 Correct 110 ms 18156 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 74 ms 7404 KB Output is correct
50 Correct 248 ms 28012 KB Output is correct
51 Correct 250 ms 28024 KB Output is correct
52 Correct 264 ms 28140 KB Output is correct
53 Correct 108 ms 18156 KB Output is correct
54 Correct 106 ms 18156 KB Output is correct
55 Correct 261 ms 28396 KB Output is correct
56 Correct 258 ms 28012 KB Output is correct
57 Correct 111 ms 18148 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 1004 KB Output is correct
61 Correct 111 ms 18284 KB Output is correct
62 Correct 1 ms 364 KB Output is correct
63 Correct 1 ms 364 KB Output is correct
64 Correct 1 ms 364 KB Output is correct
65 Correct 62 ms 7276 KB Output is correct
66 Correct 107 ms 18156 KB Output is correct
67 Correct 114 ms 18156 KB Output is correct
68 Correct 106 ms 18156 KB Output is correct
69 Correct 110 ms 18284 KB Output is correct
# Verdict Execution time Memory 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 10 ms 1516 KB Output is correct
7 Correct 281 ms 26092 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 14 ms 1388 KB Output is correct
13 Correct 270 ms 26240 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 1004 KB Output is correct
17 Correct 111 ms 16108 KB Output is correct
18 Correct 0 ms 364 KB Output is correct
19 Correct 0 ms 364 KB Output is correct
20 Correct 61 ms 6892 KB Output is correct
21 Correct 273 ms 26092 KB Output is correct
22 Correct 262 ms 26092 KB Output is correct
23 Correct 256 ms 26048 KB Output is correct
24 Correct 249 ms 26092 KB Output is correct
25 Correct 105 ms 16108 KB Output is correct
26 Correct 104 ms 16108 KB Output is correct
27 Correct 259 ms 26092 KB Output is correct
28 Correct 246 ms 26092 KB Output is correct
29 Correct 0 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 0 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 10 ms 1516 KB Output is correct
37 Correct 256 ms 28140 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 10 ms 1516 KB Output is correct
41 Correct 249 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 5 ms 1004 KB Output is correct
45 Correct 110 ms 18156 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 74 ms 7404 KB Output is correct
50 Correct 248 ms 28012 KB Output is correct
51 Correct 250 ms 28024 KB Output is correct
52 Correct 264 ms 28140 KB Output is correct
53 Correct 108 ms 18156 KB Output is correct
54 Correct 106 ms 18156 KB Output is correct
55 Correct 261 ms 28396 KB Output is correct
56 Correct 258 ms 28012 KB Output is correct
57 Correct 111 ms 18148 KB Output is correct
58 Correct 0 ms 364 KB Output is correct
59 Correct 1 ms 364 KB Output is correct
60 Correct 1 ms 268 KB Output is correct
61 Correct 62 ms 6892 KB Output is correct
62 Correct 256 ms 26092 KB Output is correct
63 Correct 256 ms 26160 KB Output is correct
64 Correct 261 ms 26212 KB Output is correct
65 Correct 1 ms 364 KB Output is correct
66 Correct 63 ms 6892 KB Output is correct
67 Correct 250 ms 26092 KB Output is correct
68 Correct 250 ms 26092 KB Output is correct
69 Correct 255 ms 26220 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 62 ms 6892 KB Output is correct
74 Correct 251 ms 26220 KB Output is correct
75 Correct 246 ms 26092 KB Output is correct
76 Correct 246 ms 26092 KB Output is correct
77 Correct 249 ms 26220 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 1004 KB Output is correct
81 Correct 111 ms 18284 KB Output is correct
82 Correct 1 ms 364 KB Output is correct
83 Correct 1 ms 364 KB Output is correct
84 Correct 1 ms 364 KB Output is correct
85 Correct 62 ms 7276 KB Output is correct
86 Correct 107 ms 18156 KB Output is correct
87 Correct 114 ms 18156 KB Output is correct
88 Correct 106 ms 18156 KB Output is correct
89 Correct 110 ms 18284 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 1004 KB Output is correct
93 Correct 112 ms 18156 KB Output is correct
94 Correct 1 ms 492 KB Output is correct
95 Correct 1 ms 364 KB Output is correct
96 Correct 1 ms 364 KB Output is correct
97 Correct 27 ms 4844 KB Output is correct
98 Correct 106 ms 18156 KB Output is correct
99 Correct 119 ms 18156 KB Output is correct
100 Correct 110 ms 18224 KB Output is correct
101 Correct 105 ms 18156 KB Output is correct
102 Correct 106 ms 18156 KB Output is correct
103 Correct 122 ms 18156 KB Output is correct
104 Correct 115 ms 18148 KB Output is correct
105 Correct 113 ms 18156 KB Output is correct