Submission #431311

# Submission time Handle Problem Language Result Execution time Memory
431311 2021-06-17T10:53:08 Z Blistering_Barnacles Connecting Supertrees (IOI20_supertrees) C++14
100 / 100
318 ms 35260 KB
#include "supertrees.h"
#include <vector>
//apig's property
//Happiness can be found, even in the darkest of times, if one only remembers to turn on the light
//El Pueblo Unido Jamas Sera Vencido
//The saddest thing about betrayal? is that it never comes from your enemies
//Do or do not... there is no try
//Billions of bilious blue blistering barnacles in a thundering typhoon!
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0)
#define F first
#define S second
#define pb push_back
#define vll vector< ll >
#define vi vector< int >
#define pll pair< ll , ll >
#define pi pair< int , int >
#define all(s) s.begin() , s.end()
#define sz(s) s.size()
#define str string
#define md ((s + e) / 2)
#define mid ((l + r) / 2)
#define msdp(dp) memset(dp , -1 , sizeof dp)
#define mscl(dp) memset(dp , 0 , sizeof dp)
#define C continue
#define R return
#define B break
#define lx node * 2
#define rx node * 2 + 1
#define br(o) o ; break
#define co(o) o ; continue
using namespace std;
typedef int ll;
ll q, par1[100005], a[555555] , par2[555555] , k, l, m, n, o, p;
map < ll , ll > mp;
const ll mod = 1e9+7;
str s;
vector < vll > ans ;
vll adj[555555] ;
ll getpar1(ll x){
    R (x == par1[x] ? x : par1[x] = getpar1(par1[x])) ;
}
void mrg1(ll x ,ll y){
    x = getpar1(x) , y = getpar1(y) ;
    if(x == y)R ;
    par1[y] = x ;
}
ll getpar2(ll x){
    R (x == par2[x] ? x : par2[x] = getpar2(par2[x])) ;
}
void mrg2(ll x , ll y){
    x = getpar2(x) , y = getpar2(y) ;
    if(x == y)R ;
    par2[y] = x ;
}
int construct(vector<vector<int>> p) {
    n = sz(p) ;
    ans.resize(n) ;
    for(ll i = 0 ; i < n ; i++){
        if(p[i][i] != 1)R 0 ;
        ans[i].resize(n) ;
        par1[i] = par2[i] = i ;
    }
    for(ll i = 0 ; i < n ; i++){
        for(ll j = i + 1 ; j < n ; j++){
            if(p[i][j] == 1)mrg1(i , j) ;
            else if(p[i][j] == 2)mrg2(i , j) ;
            else if(p[i][j] == 3)R 0 ;
        }
    }
    for(ll i = 0 ; i < n ; i++){
        if(par1[i] == i){
            ll op = getpar2(i) ;
            adj[op].pb(i) ;
            C ;
        }
        ll op = getpar1(i) ;
        ans[op][i] = ans[i][op] = 1 ;
    }
    for(ll i = 0 ; i < n ; i++){
        m = sz(adj[i]) ;
        if(m <= 1)C ;
        if(m == 2)R 0 ;
        for(ll j = 0 ; j < m ; j++){
            ll j1 = adj[i][j] , j2 = adj[i][(j + 1) % m] ;
            //cout << j1 << " " << j2 << endl ;
            ans[j1][j2] = ans[j2][j1] = 1 ;
        }
    }
    for(ll i = 0; i < n ; i++){
        for(ll j = i + 1 ; j < n ; j++){
            ll o1 = getpar1(i) , o2 = getpar1(j) ;
            if(o1 == o2 && p[i][j] != 1)R 0 ;
            ll o3 = getpar2(i) , o4 = getpar2(j) ;
            if(p[i][j] == 0 && (o1 == o2 || o3 == o4))R 0 ;
            if(p[i][j] == 2 && o1 == o2)R 0 ;
        }
    }
    for(ll i = 0 ; i < n ; i++)ans[i][i] = 0 ;
    build(ans) ;
    R 1 ;
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 13260 KB Output is correct
2 Correct 9 ms 13260 KB Output is correct
3 Correct 10 ms 13260 KB Output is correct
4 Correct 10 ms 13260 KB Output is correct
5 Correct 11 ms 13260 KB Output is correct
6 Correct 21 ms 14192 KB Output is correct
7 Correct 269 ms 35080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 13260 KB Output is correct
2 Correct 9 ms 13260 KB Output is correct
3 Correct 10 ms 13260 KB Output is correct
4 Correct 10 ms 13260 KB Output is correct
5 Correct 11 ms 13260 KB Output is correct
6 Correct 21 ms 14192 KB Output is correct
7 Correct 269 ms 35080 KB Output is correct
8 Correct 9 ms 13260 KB Output is correct
9 Correct 9 ms 13260 KB Output is correct
10 Correct 9 ms 13260 KB Output is correct
11 Correct 9 ms 13260 KB Output is correct
12 Correct 18 ms 14236 KB Output is correct
13 Correct 246 ms 35100 KB Output is correct
14 Correct 9 ms 13260 KB Output is correct
15 Correct 10 ms 13260 KB Output is correct
16 Correct 17 ms 13760 KB Output is correct
17 Correct 137 ms 25096 KB Output is correct
18 Correct 10 ms 13260 KB Output is correct
19 Correct 11 ms 13340 KB Output is correct
20 Correct 77 ms 18832 KB Output is correct
21 Correct 262 ms 35064 KB Output is correct
22 Correct 260 ms 35068 KB Output is correct
23 Correct 278 ms 35112 KB Output is correct
24 Correct 254 ms 35260 KB Output is correct
25 Correct 117 ms 25096 KB Output is correct
26 Correct 105 ms 25152 KB Output is correct
27 Correct 266 ms 35068 KB Output is correct
28 Correct 252 ms 35024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 13260 KB Output is correct
2 Correct 10 ms 13260 KB Output is correct
3 Correct 9 ms 13260 KB Output is correct
4 Correct 9 ms 13260 KB Output is correct
5 Correct 11 ms 13292 KB Output is correct
6 Correct 10 ms 13260 KB Output is correct
7 Correct 10 ms 13260 KB Output is correct
8 Correct 23 ms 14216 KB Output is correct
9 Correct 269 ms 35064 KB Output is correct
10 Correct 10 ms 13260 KB Output is correct
11 Correct 10 ms 13260 KB Output is correct
12 Correct 19 ms 14180 KB Output is correct
13 Correct 250 ms 35052 KB Output is correct
14 Correct 10 ms 13260 KB Output is correct
15 Correct 9 ms 13260 KB Output is correct
16 Correct 14 ms 13720 KB Output is correct
17 Correct 147 ms 25080 KB Output is correct
18 Correct 9 ms 13260 KB Output is correct
19 Correct 9 ms 13260 KB Output is correct
20 Correct 9 ms 13312 KB Output is correct
21 Correct 76 ms 18812 KB Output is correct
22 Correct 306 ms 35112 KB Output is correct
23 Correct 261 ms 34996 KB Output is correct
24 Correct 318 ms 35068 KB Output is correct
25 Correct 140 ms 25108 KB Output is correct
26 Correct 110 ms 25084 KB Output is correct
27 Correct 250 ms 35084 KB Output is correct
28 Correct 277 ms 35120 KB Output is correct
29 Correct 104 ms 25220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 13260 KB Output is correct
2 Correct 11 ms 13260 KB Output is correct
3 Correct 10 ms 13260 KB Output is correct
4 Correct 73 ms 18764 KB Output is correct
5 Correct 250 ms 35088 KB Output is correct
6 Correct 251 ms 35080 KB Output is correct
7 Correct 259 ms 35168 KB Output is correct
8 Correct 10 ms 13260 KB Output is correct
9 Correct 78 ms 18748 KB Output is correct
10 Correct 250 ms 35120 KB Output is correct
11 Correct 250 ms 35000 KB Output is correct
12 Correct 270 ms 35116 KB Output is correct
13 Correct 9 ms 13340 KB Output is correct
14 Correct 11 ms 13360 KB Output is correct
15 Correct 9 ms 13260 KB Output is correct
16 Correct 83 ms 18756 KB Output is correct
17 Correct 285 ms 35112 KB Output is correct
18 Correct 251 ms 35068 KB Output is correct
19 Correct 245 ms 35116 KB Output is correct
20 Correct 243 ms 35036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 13260 KB Output is correct
2 Correct 9 ms 13260 KB Output is correct
3 Correct 10 ms 13260 KB Output is correct
4 Correct 10 ms 13260 KB Output is correct
5 Correct 11 ms 13260 KB Output is correct
6 Correct 21 ms 14192 KB Output is correct
7 Correct 269 ms 35080 KB Output is correct
8 Correct 9 ms 13260 KB Output is correct
9 Correct 9 ms 13260 KB Output is correct
10 Correct 9 ms 13260 KB Output is correct
11 Correct 9 ms 13260 KB Output is correct
12 Correct 18 ms 14236 KB Output is correct
13 Correct 246 ms 35100 KB Output is correct
14 Correct 9 ms 13260 KB Output is correct
15 Correct 10 ms 13260 KB Output is correct
16 Correct 17 ms 13760 KB Output is correct
17 Correct 137 ms 25096 KB Output is correct
18 Correct 10 ms 13260 KB Output is correct
19 Correct 11 ms 13340 KB Output is correct
20 Correct 77 ms 18832 KB Output is correct
21 Correct 262 ms 35064 KB Output is correct
22 Correct 260 ms 35068 KB Output is correct
23 Correct 278 ms 35112 KB Output is correct
24 Correct 254 ms 35260 KB Output is correct
25 Correct 117 ms 25096 KB Output is correct
26 Correct 105 ms 25152 KB Output is correct
27 Correct 266 ms 35068 KB Output is correct
28 Correct 252 ms 35024 KB Output is correct
29 Correct 10 ms 13260 KB Output is correct
30 Correct 10 ms 13260 KB Output is correct
31 Correct 9 ms 13260 KB Output is correct
32 Correct 9 ms 13260 KB Output is correct
33 Correct 11 ms 13292 KB Output is correct
34 Correct 10 ms 13260 KB Output is correct
35 Correct 10 ms 13260 KB Output is correct
36 Correct 23 ms 14216 KB Output is correct
37 Correct 269 ms 35064 KB Output is correct
38 Correct 10 ms 13260 KB Output is correct
39 Correct 10 ms 13260 KB Output is correct
40 Correct 19 ms 14180 KB Output is correct
41 Correct 250 ms 35052 KB Output is correct
42 Correct 10 ms 13260 KB Output is correct
43 Correct 9 ms 13260 KB Output is correct
44 Correct 14 ms 13720 KB Output is correct
45 Correct 147 ms 25080 KB Output is correct
46 Correct 9 ms 13260 KB Output is correct
47 Correct 9 ms 13260 KB Output is correct
48 Correct 9 ms 13312 KB Output is correct
49 Correct 76 ms 18812 KB Output is correct
50 Correct 306 ms 35112 KB Output is correct
51 Correct 261 ms 34996 KB Output is correct
52 Correct 318 ms 35068 KB Output is correct
53 Correct 140 ms 25108 KB Output is correct
54 Correct 110 ms 25084 KB Output is correct
55 Correct 250 ms 35084 KB Output is correct
56 Correct 277 ms 35120 KB Output is correct
57 Correct 104 ms 25220 KB Output is correct
58 Correct 10 ms 13288 KB Output is correct
59 Correct 9 ms 13260 KB Output is correct
60 Correct 13 ms 13772 KB Output is correct
61 Correct 117 ms 25184 KB Output is correct
62 Correct 10 ms 13260 KB Output is correct
63 Correct 11 ms 13344 KB Output is correct
64 Correct 10 ms 13260 KB Output is correct
65 Correct 75 ms 18832 KB Output is correct
66 Correct 117 ms 25084 KB Output is correct
67 Correct 131 ms 25084 KB Output is correct
68 Correct 123 ms 25080 KB Output is correct
69 Correct 110 ms 25212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 13260 KB Output is correct
2 Correct 9 ms 13260 KB Output is correct
3 Correct 10 ms 13260 KB Output is correct
4 Correct 10 ms 13260 KB Output is correct
5 Correct 11 ms 13260 KB Output is correct
6 Correct 21 ms 14192 KB Output is correct
7 Correct 269 ms 35080 KB Output is correct
8 Correct 9 ms 13260 KB Output is correct
9 Correct 9 ms 13260 KB Output is correct
10 Correct 9 ms 13260 KB Output is correct
11 Correct 9 ms 13260 KB Output is correct
12 Correct 18 ms 14236 KB Output is correct
13 Correct 246 ms 35100 KB Output is correct
14 Correct 9 ms 13260 KB Output is correct
15 Correct 10 ms 13260 KB Output is correct
16 Correct 17 ms 13760 KB Output is correct
17 Correct 137 ms 25096 KB Output is correct
18 Correct 10 ms 13260 KB Output is correct
19 Correct 11 ms 13340 KB Output is correct
20 Correct 77 ms 18832 KB Output is correct
21 Correct 262 ms 35064 KB Output is correct
22 Correct 260 ms 35068 KB Output is correct
23 Correct 278 ms 35112 KB Output is correct
24 Correct 254 ms 35260 KB Output is correct
25 Correct 117 ms 25096 KB Output is correct
26 Correct 105 ms 25152 KB Output is correct
27 Correct 266 ms 35068 KB Output is correct
28 Correct 252 ms 35024 KB Output is correct
29 Correct 10 ms 13260 KB Output is correct
30 Correct 10 ms 13260 KB Output is correct
31 Correct 9 ms 13260 KB Output is correct
32 Correct 9 ms 13260 KB Output is correct
33 Correct 11 ms 13292 KB Output is correct
34 Correct 10 ms 13260 KB Output is correct
35 Correct 10 ms 13260 KB Output is correct
36 Correct 23 ms 14216 KB Output is correct
37 Correct 269 ms 35064 KB Output is correct
38 Correct 10 ms 13260 KB Output is correct
39 Correct 10 ms 13260 KB Output is correct
40 Correct 19 ms 14180 KB Output is correct
41 Correct 250 ms 35052 KB Output is correct
42 Correct 10 ms 13260 KB Output is correct
43 Correct 9 ms 13260 KB Output is correct
44 Correct 14 ms 13720 KB Output is correct
45 Correct 147 ms 25080 KB Output is correct
46 Correct 9 ms 13260 KB Output is correct
47 Correct 9 ms 13260 KB Output is correct
48 Correct 9 ms 13312 KB Output is correct
49 Correct 76 ms 18812 KB Output is correct
50 Correct 306 ms 35112 KB Output is correct
51 Correct 261 ms 34996 KB Output is correct
52 Correct 318 ms 35068 KB Output is correct
53 Correct 140 ms 25108 KB Output is correct
54 Correct 110 ms 25084 KB Output is correct
55 Correct 250 ms 35084 KB Output is correct
56 Correct 277 ms 35120 KB Output is correct
57 Correct 104 ms 25220 KB Output is correct
58 Correct 9 ms 13260 KB Output is correct
59 Correct 11 ms 13260 KB Output is correct
60 Correct 10 ms 13260 KB Output is correct
61 Correct 73 ms 18764 KB Output is correct
62 Correct 250 ms 35088 KB Output is correct
63 Correct 251 ms 35080 KB Output is correct
64 Correct 259 ms 35168 KB Output is correct
65 Correct 10 ms 13260 KB Output is correct
66 Correct 78 ms 18748 KB Output is correct
67 Correct 250 ms 35120 KB Output is correct
68 Correct 250 ms 35000 KB Output is correct
69 Correct 270 ms 35116 KB Output is correct
70 Correct 9 ms 13340 KB Output is correct
71 Correct 11 ms 13360 KB Output is correct
72 Correct 9 ms 13260 KB Output is correct
73 Correct 83 ms 18756 KB Output is correct
74 Correct 285 ms 35112 KB Output is correct
75 Correct 251 ms 35068 KB Output is correct
76 Correct 245 ms 35116 KB Output is correct
77 Correct 243 ms 35036 KB Output is correct
78 Correct 10 ms 13288 KB Output is correct
79 Correct 9 ms 13260 KB Output is correct
80 Correct 13 ms 13772 KB Output is correct
81 Correct 117 ms 25184 KB Output is correct
82 Correct 10 ms 13260 KB Output is correct
83 Correct 11 ms 13344 KB Output is correct
84 Correct 10 ms 13260 KB Output is correct
85 Correct 75 ms 18832 KB Output is correct
86 Correct 117 ms 25084 KB Output is correct
87 Correct 131 ms 25084 KB Output is correct
88 Correct 123 ms 25080 KB Output is correct
89 Correct 110 ms 25212 KB Output is correct
90 Correct 8 ms 13248 KB Output is correct
91 Correct 10 ms 13260 KB Output is correct
92 Correct 13 ms 13764 KB Output is correct
93 Correct 143 ms 25100 KB Output is correct
94 Correct 9 ms 13260 KB Output is correct
95 Correct 9 ms 13296 KB Output is correct
96 Correct 9 ms 13260 KB Output is correct
97 Correct 34 ms 16324 KB Output is correct
98 Correct 108 ms 25196 KB Output is correct
99 Correct 128 ms 25084 KB Output is correct
100 Correct 107 ms 25084 KB Output is correct
101 Correct 116 ms 25084 KB Output is correct
102 Correct 103 ms 25104 KB Output is correct
103 Correct 112 ms 25116 KB Output is correct
104 Correct 122 ms 25084 KB Output is correct
105 Correct 118 ms 25200 KB Output is correct