Submission #1050037

# Submission time Handle Problem Language Result Execution time Memory
1050037 2024-08-09T06:58:33 Z AlperenT_ Connecting Supertrees (IOI20_supertrees) C++17
100 / 100
171 ms 40808 KB
#include "supertrees.h"
#include <bits/stdc++.h>
 

#pragma GCC optimize("O3,unroll-loops")
#define pb push_back
#define F first
#define S second 
#define all(a) a.begin(),a.end()
#define pii pair <int,int>
#define ld long double 
#define sz(v) (int)v.size()
#define rep(i , a , b) for(int i=a;i <= b;i++)
#define per(i, a , b) for(int i=a;i >= b;i--)
using namespace std ;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 2000 + 10  , sq = 333   , inf = 2e9 +100 , maxk = 2022 , mod = 1e9 + 7 ;
int n , ok =1 , cnt2 = 1 ,  cnt = 1  , mark[maxn] ,p[maxn][maxn] , b[maxn][maxn]  , c[maxn] , ye[maxn] , c2[maxn] ;
vector <int> vec ;

void dfs(int v){
    vec.pb(v) ;
    c[v] = cnt ; 
    mark[v] =1 ; 
    rep(j , 0 ,n-1){
        if(mark[j]==0 && p[v][j]){
            dfs(j) ; 
        }
    }
}
vector <int> vec2 ; 
void dfs2(int v){
    mark[v] =1 ;
    c2[v] = cnt2 ; 
    ye[cnt2] = v;  
    for(int u :  vec2){
        if(mark[u]==1 || p[v][u] == 2)continue ; 
        dfs2(u) ;
    }
}
void add(int x ,int y){
    b[x][y] = b[y][x] =1 ;
}

bool ch(vector <int> vec){
    vec2 = vec ;
    cnt2 = 1 ;
    for(int x : vec)mark[x] =0 ;
    for(int x : vec){
        if(mark[x] == 1)continue ;
        dfs2(x) ;
        cnt2++ ;
    }
    cnt2--;
    for(int x : vec){
        for(int y : vec){
            if(c2[x] == c2[y] && p[x][y] == 2)return 0 ;
        }
    }
    rep(i , 1 ,cnt2){
        vector <int> az ;
        for(int x : vec){
            if(c2[x] == i)az.pb(x);
        }
        rep(j ,1 ,sz(az)-1)add(az[j-1],az[j]) ;
    }
    if(cnt2==1)return 1 ; 
    if(cnt2 == 2){
        if(sz(vec)==2)return 0 ;
        vector <int> a[2] ;
        for(int v : vec){
            a[c2[v]-1].pb(v) ;
        }   
        if(sz(a[0]) > sz(a[1]))swap(a[0] , a[1]) ;
        add(a[0][0] , a[1][0]) ;
        add(a[0][0] , a[1][1]) ; 
        return 1 ;
    }
    add(ye[1],ye[cnt2]) ;
    rep(i ,2 , cnt2){
        add(ye[i-1] , ye[i]);
    }
    return 1 ;
}

int construct(vector<std::vector<int>> pp) {
    n = sz(pp);
    rep(i , 0 , n-1){
        rep(j , 0 ,n-1){
            p[i][j] = pp[i][j] ;
            if(p[i][j] == 3)return 0 ;
        }
    }
    rep(i ,0 , n-1){
        if(mark[i] == 1)continue ; 
        dfs(i) ;
        cnt++;
    }
    cnt--;
    rep(i ,0  ,n-1){
        rep(j , 0 ,n-1){
            if((c[i]==c[j] && p[i][j]==0) || (c[i]!=c[j] && p[i][j]>0))return 0 ;
        }
    }
    rep(i , 1, cnt){
        vector <int> vec;
        rep(j , 0 , n-1){
            if(c[j] == i){
                vec.pb(j) ;
            }
        }
        if(ch(vec)==0)return 0 ;
    }
    vector <vector <int> > bb ;
    rep(i , 0 , n-1){
        vector <int> f ;
        rep(j , 0, n-1){
            f.pb(b[i][j]) ;
        }
        bb.pb(f) ;
    }
    build(bb) ;
    return 1 ; 
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2404 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 5 ms 7516 KB Output is correct
7 Correct 114 ms 40736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2404 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 5 ms 7516 KB Output is correct
7 Correct 114 ms 40736 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 4 ms 5212 KB Output is correct
13 Correct 92 ms 32340 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 3 ms 4700 KB Output is correct
17 Correct 45 ms 18464 KB Output is correct
18 Correct 0 ms 2392 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 25 ms 16192 KB Output is correct
21 Correct 94 ms 40616 KB Output is correct
22 Correct 94 ms 40740 KB Output is correct
23 Correct 129 ms 40784 KB Output is correct
24 Correct 92 ms 40528 KB Output is correct
25 Correct 41 ms 18452 KB Output is correct
26 Correct 39 ms 18516 KB Output is correct
27 Correct 171 ms 40792 KB Output is correct
28 Correct 107 ms 40480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 4 ms 5392 KB Output is correct
9 Correct 104 ms 32280 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 4 ms 7516 KB Output is correct
13 Correct 107 ms 40780 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 2 ms 4872 KB Output is correct
17 Correct 64 ms 18516 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 30 ms 16068 KB Output is correct
22 Correct 101 ms 40732 KB Output is correct
23 Correct 95 ms 40784 KB Output is correct
24 Correct 105 ms 40736 KB Output is correct
25 Correct 41 ms 26708 KB Output is correct
26 Correct 42 ms 18512 KB Output is correct
27 Correct 100 ms 40680 KB Output is correct
28 Correct 99 ms 40788 KB Output is correct
29 Correct 44 ms 26704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 24 ms 16176 KB Output is correct
5 Correct 96 ms 40736 KB Output is correct
6 Correct 107 ms 40532 KB Output is correct
7 Correct 124 ms 40784 KB Output is correct
8 Correct 0 ms 2392 KB Output is correct
9 Correct 25 ms 16048 KB Output is correct
10 Correct 99 ms 40808 KB Output is correct
11 Correct 92 ms 40784 KB Output is correct
12 Correct 100 ms 40784 KB Output is correct
13 Correct 0 ms 2392 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 25 ms 16220 KB Output is correct
17 Correct 93 ms 40740 KB Output is correct
18 Correct 97 ms 40784 KB Output is correct
19 Correct 94 ms 40784 KB Output is correct
20 Correct 92 ms 40532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2404 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 5 ms 7516 KB Output is correct
7 Correct 114 ms 40736 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 4 ms 5212 KB Output is correct
13 Correct 92 ms 32340 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 3 ms 4700 KB Output is correct
17 Correct 45 ms 18464 KB Output is correct
18 Correct 0 ms 2392 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 25 ms 16192 KB Output is correct
21 Correct 94 ms 40616 KB Output is correct
22 Correct 94 ms 40740 KB Output is correct
23 Correct 129 ms 40784 KB Output is correct
24 Correct 92 ms 40528 KB Output is correct
25 Correct 41 ms 18452 KB Output is correct
26 Correct 39 ms 18516 KB Output is correct
27 Correct 171 ms 40792 KB Output is correct
28 Correct 107 ms 40480 KB Output is correct
29 Correct 0 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 0 ms 2396 KB Output is correct
32 Correct 0 ms 2396 KB Output is correct
33 Correct 0 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 4 ms 5392 KB Output is correct
37 Correct 104 ms 32280 KB Output is correct
38 Correct 0 ms 2396 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
40 Correct 4 ms 7516 KB Output is correct
41 Correct 107 ms 40780 KB Output is correct
42 Correct 0 ms 2396 KB Output is correct
43 Correct 0 ms 2396 KB Output is correct
44 Correct 2 ms 4872 KB Output is correct
45 Correct 64 ms 18516 KB Output is correct
46 Correct 0 ms 2396 KB Output is correct
47 Correct 1 ms 2396 KB Output is correct
48 Correct 0 ms 2396 KB Output is correct
49 Correct 30 ms 16068 KB Output is correct
50 Correct 101 ms 40732 KB Output is correct
51 Correct 95 ms 40784 KB Output is correct
52 Correct 105 ms 40736 KB Output is correct
53 Correct 41 ms 26708 KB Output is correct
54 Correct 42 ms 18512 KB Output is correct
55 Correct 100 ms 40680 KB Output is correct
56 Correct 99 ms 40788 KB Output is correct
57 Correct 44 ms 26704 KB Output is correct
58 Correct 1 ms 2392 KB Output is correct
59 Correct 0 ms 2396 KB Output is correct
60 Correct 4 ms 4700 KB Output is correct
61 Correct 57 ms 18468 KB Output is correct
62 Correct 0 ms 2396 KB Output is correct
63 Correct 0 ms 2396 KB Output is correct
64 Correct 0 ms 2396 KB Output is correct
65 Correct 24 ms 16144 KB Output is correct
66 Correct 40 ms 18524 KB Output is correct
67 Correct 41 ms 18464 KB Output is correct
68 Correct 42 ms 18468 KB Output is correct
69 Correct 42 ms 26780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2404 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 5 ms 7516 KB Output is correct
7 Correct 114 ms 40736 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 4 ms 5212 KB Output is correct
13 Correct 92 ms 32340 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 3 ms 4700 KB Output is correct
17 Correct 45 ms 18464 KB Output is correct
18 Correct 0 ms 2392 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 25 ms 16192 KB Output is correct
21 Correct 94 ms 40616 KB Output is correct
22 Correct 94 ms 40740 KB Output is correct
23 Correct 129 ms 40784 KB Output is correct
24 Correct 92 ms 40528 KB Output is correct
25 Correct 41 ms 18452 KB Output is correct
26 Correct 39 ms 18516 KB Output is correct
27 Correct 171 ms 40792 KB Output is correct
28 Correct 107 ms 40480 KB Output is correct
29 Correct 0 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 0 ms 2396 KB Output is correct
32 Correct 0 ms 2396 KB Output is correct
33 Correct 0 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 4 ms 5392 KB Output is correct
37 Correct 104 ms 32280 KB Output is correct
38 Correct 0 ms 2396 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
40 Correct 4 ms 7516 KB Output is correct
41 Correct 107 ms 40780 KB Output is correct
42 Correct 0 ms 2396 KB Output is correct
43 Correct 0 ms 2396 KB Output is correct
44 Correct 2 ms 4872 KB Output is correct
45 Correct 64 ms 18516 KB Output is correct
46 Correct 0 ms 2396 KB Output is correct
47 Correct 1 ms 2396 KB Output is correct
48 Correct 0 ms 2396 KB Output is correct
49 Correct 30 ms 16068 KB Output is correct
50 Correct 101 ms 40732 KB Output is correct
51 Correct 95 ms 40784 KB Output is correct
52 Correct 105 ms 40736 KB Output is correct
53 Correct 41 ms 26708 KB Output is correct
54 Correct 42 ms 18512 KB Output is correct
55 Correct 100 ms 40680 KB Output is correct
56 Correct 99 ms 40788 KB Output is correct
57 Correct 44 ms 26704 KB Output is correct
58 Correct 0 ms 2392 KB Output is correct
59 Correct 0 ms 2396 KB Output is correct
60 Correct 0 ms 2396 KB Output is correct
61 Correct 24 ms 16176 KB Output is correct
62 Correct 96 ms 40736 KB Output is correct
63 Correct 107 ms 40532 KB Output is correct
64 Correct 124 ms 40784 KB Output is correct
65 Correct 0 ms 2392 KB Output is correct
66 Correct 25 ms 16048 KB Output is correct
67 Correct 99 ms 40808 KB Output is correct
68 Correct 92 ms 40784 KB Output is correct
69 Correct 100 ms 40784 KB Output is correct
70 Correct 0 ms 2392 KB Output is correct
71 Correct 0 ms 2396 KB Output is correct
72 Correct 0 ms 2396 KB Output is correct
73 Correct 25 ms 16220 KB Output is correct
74 Correct 93 ms 40740 KB Output is correct
75 Correct 97 ms 40784 KB Output is correct
76 Correct 94 ms 40784 KB Output is correct
77 Correct 92 ms 40532 KB Output is correct
78 Correct 1 ms 2392 KB Output is correct
79 Correct 0 ms 2396 KB Output is correct
80 Correct 4 ms 4700 KB Output is correct
81 Correct 57 ms 18468 KB Output is correct
82 Correct 0 ms 2396 KB Output is correct
83 Correct 0 ms 2396 KB Output is correct
84 Correct 0 ms 2396 KB Output is correct
85 Correct 24 ms 16144 KB Output is correct
86 Correct 40 ms 18524 KB Output is correct
87 Correct 41 ms 18464 KB Output is correct
88 Correct 42 ms 18468 KB Output is correct
89 Correct 42 ms 26780 KB Output is correct
90 Correct 1 ms 2396 KB Output is correct
91 Correct 0 ms 2396 KB Output is correct
92 Correct 2 ms 2652 KB Output is correct
93 Correct 44 ms 10272 KB Output is correct
94 Correct 0 ms 2396 KB Output is correct
95 Correct 0 ms 2396 KB Output is correct
96 Correct 0 ms 2396 KB Output is correct
97 Correct 10 ms 4256 KB Output is correct
98 Correct 44 ms 10288 KB Output is correct
99 Correct 47 ms 12372 KB Output is correct
100 Correct 38 ms 10324 KB Output is correct
101 Correct 38 ms 12320 KB Output is correct
102 Correct 42 ms 10320 KB Output is correct
103 Correct 38 ms 10324 KB Output is correct
104 Correct 52 ms 10324 KB Output is correct
105 Correct 46 ms 10324 KB Output is correct