Submission #546875

# Submission time Handle Problem Language Result Execution time Memory
546875 2022-04-08T18:18:46 Z urosk Connecting Supertrees (IOI20_supertrees) C++14
100 / 100
244 ms 32076 KB
#include "supertrees.h"
#include "bits/stdc++.h"
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define ld double
#define ll long long
#define ull unsigned long long
#define llinf 100000000000000000LL // 10^17
#define iinf 2000000000 // 2*10^9
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) ((ll)(a.size()))
#define all(a) a.begin(),a.end()
#define rall(a) a.begin(),a.end(),greater<int>()
#define getunique(v) {sort(all(v)); v.erase(unique(all(v)), v.end());}
#define pi 3.14159265358979323846
#define here cerr<<"=============================================================================\n"
#define ceri(a,l,r) {for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
#define ceri2(a,l,r,n,m) {for(ll i = l;i<=r;i++){for(ll j = n;j<=m;j++) cerr<<a[i][j]<< " ";cerr<<endl;}}
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define daj_mi_malo_vremena ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
using namespace std;
#define maxn 1005
ll dsu[maxn];
ll root(ll x){
    while(x!=dsu[x]){
        dsu[x] = dsu[dsu[x]];
        x = dsu[x];
    }
    return x;
}
void upd(ll x,ll y){dsu[root(x)] = root(y);}
bool get(ll x,ll y){return root(x)==root(y);}
vector<ll> v[maxn];
vector<std::vector<int>> answer;
bool cyc[maxn];
void upd2(ll x,ll y){
    answer[x][y] = 1;
    answer[y][x] = 1;
    cyc[y] = 1;
    cyc[x] = 1;
}
bool bio[maxn];
bool vis[maxn];
vector<ll> g[maxn];
ll d[maxn][maxn];
void dfs(ll poc,ll par,ll u){
    //cerr<<poc<< " "<<par<<endl;
    for(ll s : g[u]){
        if(vis[s]) continue;
        d[poc][s]++;
        vis[s] = 1;
        dfs(poc,u,s);
        vis[s] = 0;
    }
}
int construct(std::vector<std::vector<int>> p) {

	int n = p.size();
	for(ll i = 0;i<n;i++){
        vector<int> w(n);
        answer.pb(w);
	}
	iota(dsu,dsu+n,0);
	for(ll i = 0;i<n;i++){
        for(ll j = 0;j<n;j++){
            if(p[i][j]==3) return 0;
        }
        for(ll j = 0;j<n;j++){
            if(p[i][j]==1) upd(i,j);
        }
	}
	vector<vector<ll> >w;
    for(ll i = 0;i<n;i++) v[root(i)].pb(i);
    for(ll i = 0;i<n;i++) if(sz(v[i])) w.pb(v[i]);
    for(ll i = 0;i<sz(w);i++){
        for(ll j = 0;j<sz(w[i])-1;j++){
            answer[w[i][j]][w[i][j+1]] = 1;
            answer[w[i][j+1]][w[i][j]] = 1;
        }
    }
    /*here;
    for(vector<ll> v : w){
        for(ll x : v) cerr<<x<< " ";
        cerr<<endl;
    }
    here;
    for(vector<int> v : answer){
        for(ll x : v) cerr<<x<< " ";
        cerr<<endl;
    }
    here;*/
    for(ll i = 0;i<sz(w);i++){
        ll last = i;
        for(ll j = i+1;j<sz(w);j++){
            if(bio[j]) continue;
            if(p[root(w[last].back())][root(w[j].back())]>0){
                upd2(w[last].back(),w[j].back());
                upd(w[last].back(),w[j].back());

                last = j;
                bio[j] = 1;
            }
        }
        if(last!=i) upd2(w[last].back(),w[i].back());
    }
    for(ll i = 0;i<n;i++){
        for(ll j = i+1;j<n;j++){
            if(answer[i][j]){
                //cerr<<i<< " "<<j<<endl;
                g[i].pb(j);
                g[j].pb(i);
            }
        }
    }
    for(ll i = 0;i<n;i++){
        vis[i] = 1;
        dfs(i,i,i);
        vis[i] = 0;
    }
    /*for(ll i = 0;i<n;i++){
        for(ll j = 0;j<n;j++) cerr<<d[i][j]<< " ";
        cerr<<endl;
    }*/
    for(ll i = 0;i<n;i++){
        d[i][i] = 1;
        for(ll j = 0;j<n;j++){
            if(d[i][j]!=p[i][j]) return 0;
        }
    }
    build(answer);
	return 1;
}
/*
4
1 1 2 2
1 1 2 2
2 2 1 2
2 2 2 1
*/
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 9 ms 2376 KB Output is correct
7 Correct 210 ms 29988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 9 ms 2376 KB Output is correct
7 Correct 210 ms 29988 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 10 ms 2056 KB Output is correct
13 Correct 180 ms 26184 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 5 ms 1876 KB Output is correct
17 Correct 103 ms 20176 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 48 ms 9408 KB Output is correct
21 Correct 195 ms 30012 KB Output is correct
22 Correct 177 ms 28620 KB Output is correct
23 Correct 244 ms 30140 KB Output is correct
24 Correct 189 ms 26480 KB Output is correct
25 Correct 93 ms 20044 KB Output is correct
26 Correct 68 ms 17356 KB Output is correct
27 Correct 202 ms 30024 KB Output is correct
28 Correct 195 ms 26396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 356 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 9 ms 2132 KB Output is correct
9 Correct 193 ms 28088 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 352 KB Output is correct
12 Correct 10 ms 2368 KB Output is correct
13 Correct 214 ms 32016 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 356 KB Output is correct
16 Correct 6 ms 2004 KB Output is correct
17 Correct 113 ms 22064 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 360 KB Output is correct
20 Correct 1 ms 356 KB Output is correct
21 Correct 50 ms 9900 KB Output is correct
22 Correct 189 ms 31984 KB Output is correct
23 Correct 186 ms 31736 KB Output is correct
24 Correct 212 ms 32008 KB Output is correct
25 Correct 78 ms 16872 KB Output is correct
26 Correct 82 ms 22084 KB Output is correct
27 Correct 175 ms 31688 KB Output is correct
28 Correct 206 ms 32076 KB Output is correct
29 Correct 78 ms 16816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 48 ms 9412 KB Output is correct
5 Correct 231 ms 29964 KB Output is correct
6 Correct 179 ms 28652 KB Output is correct
7 Correct 241 ms 29948 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 50 ms 9420 KB Output is correct
10 Correct 202 ms 30156 KB Output is correct
11 Correct 180 ms 29812 KB Output is correct
12 Correct 220 ms 30156 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 46 ms 9300 KB Output is correct
17 Correct 188 ms 30028 KB Output is correct
18 Correct 190 ms 30024 KB Output is correct
19 Correct 211 ms 30024 KB Output is correct
20 Correct 175 ms 26444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 9 ms 2376 KB Output is correct
7 Correct 210 ms 29988 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 10 ms 2056 KB Output is correct
13 Correct 180 ms 26184 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 5 ms 1876 KB Output is correct
17 Correct 103 ms 20176 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 48 ms 9408 KB Output is correct
21 Correct 195 ms 30012 KB Output is correct
22 Correct 177 ms 28620 KB Output is correct
23 Correct 244 ms 30140 KB Output is correct
24 Correct 189 ms 26480 KB Output is correct
25 Correct 93 ms 20044 KB Output is correct
26 Correct 68 ms 17356 KB Output is correct
27 Correct 202 ms 30024 KB Output is correct
28 Correct 195 ms 26396 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 1 ms 356 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 9 ms 2132 KB Output is correct
37 Correct 193 ms 28088 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 352 KB Output is correct
40 Correct 10 ms 2368 KB Output is correct
41 Correct 214 ms 32016 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 1 ms 356 KB Output is correct
44 Correct 6 ms 2004 KB Output is correct
45 Correct 113 ms 22064 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 360 KB Output is correct
48 Correct 1 ms 356 KB Output is correct
49 Correct 50 ms 9900 KB Output is correct
50 Correct 189 ms 31984 KB Output is correct
51 Correct 186 ms 31736 KB Output is correct
52 Correct 212 ms 32008 KB Output is correct
53 Correct 78 ms 16872 KB Output is correct
54 Correct 82 ms 22084 KB Output is correct
55 Correct 175 ms 31688 KB Output is correct
56 Correct 206 ms 32076 KB Output is correct
57 Correct 78 ms 16816 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 8 ms 2004 KB Output is correct
61 Correct 116 ms 22076 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 364 KB Output is correct
65 Correct 47 ms 9704 KB Output is correct
66 Correct 79 ms 22060 KB Output is correct
67 Correct 92 ms 22196 KB Output is correct
68 Correct 86 ms 22064 KB Output is correct
69 Correct 82 ms 14904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 9 ms 2376 KB Output is correct
7 Correct 210 ms 29988 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 10 ms 2056 KB Output is correct
13 Correct 180 ms 26184 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 5 ms 1876 KB Output is correct
17 Correct 103 ms 20176 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 48 ms 9408 KB Output is correct
21 Correct 195 ms 30012 KB Output is correct
22 Correct 177 ms 28620 KB Output is correct
23 Correct 244 ms 30140 KB Output is correct
24 Correct 189 ms 26480 KB Output is correct
25 Correct 93 ms 20044 KB Output is correct
26 Correct 68 ms 17356 KB Output is correct
27 Correct 202 ms 30024 KB Output is correct
28 Correct 195 ms 26396 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 1 ms 356 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 9 ms 2132 KB Output is correct
37 Correct 193 ms 28088 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 352 KB Output is correct
40 Correct 10 ms 2368 KB Output is correct
41 Correct 214 ms 32016 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 1 ms 356 KB Output is correct
44 Correct 6 ms 2004 KB Output is correct
45 Correct 113 ms 22064 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 360 KB Output is correct
48 Correct 1 ms 356 KB Output is correct
49 Correct 50 ms 9900 KB Output is correct
50 Correct 189 ms 31984 KB Output is correct
51 Correct 186 ms 31736 KB Output is correct
52 Correct 212 ms 32008 KB Output is correct
53 Correct 78 ms 16872 KB Output is correct
54 Correct 82 ms 22084 KB Output is correct
55 Correct 175 ms 31688 KB Output is correct
56 Correct 206 ms 32076 KB Output is correct
57 Correct 78 ms 16816 KB Output is correct
58 Correct 0 ms 340 KB Output is correct
59 Correct 0 ms 340 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 48 ms 9412 KB Output is correct
62 Correct 231 ms 29964 KB Output is correct
63 Correct 179 ms 28652 KB Output is correct
64 Correct 241 ms 29948 KB Output is correct
65 Correct 1 ms 340 KB Output is correct
66 Correct 50 ms 9420 KB Output is correct
67 Correct 202 ms 30156 KB Output is correct
68 Correct 180 ms 29812 KB Output is correct
69 Correct 220 ms 30156 KB Output is correct
70 Correct 0 ms 340 KB Output is correct
71 Correct 0 ms 340 KB Output is correct
72 Correct 0 ms 340 KB Output is correct
73 Correct 46 ms 9300 KB Output is correct
74 Correct 188 ms 30028 KB Output is correct
75 Correct 190 ms 30024 KB Output is correct
76 Correct 211 ms 30024 KB Output is correct
77 Correct 175 ms 26444 KB Output is correct
78 Correct 1 ms 340 KB Output is correct
79 Correct 1 ms 340 KB Output is correct
80 Correct 8 ms 2004 KB Output is correct
81 Correct 116 ms 22076 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 364 KB Output is correct
85 Correct 47 ms 9704 KB Output is correct
86 Correct 79 ms 22060 KB Output is correct
87 Correct 92 ms 22196 KB Output is correct
88 Correct 86 ms 22064 KB Output is correct
89 Correct 82 ms 14904 KB Output is correct
90 Correct 1 ms 340 KB Output is correct
91 Correct 1 ms 340 KB Output is correct
92 Correct 4 ms 852 KB Output is correct
93 Correct 91 ms 14132 KB Output is correct
94 Correct 1 ms 340 KB Output is correct
95 Correct 1 ms 340 KB Output is correct
96 Correct 1 ms 340 KB Output is correct
97 Correct 20 ms 3768 KB Output is correct
98 Correct 74 ms 14260 KB Output is correct
99 Correct 80 ms 14132 KB Output is correct
100 Correct 71 ms 14140 KB Output is correct
101 Correct 72 ms 14140 KB Output is correct
102 Correct 83 ms 14132 KB Output is correct
103 Correct 83 ms 14144 KB Output is correct
104 Correct 87 ms 14132 KB Output is correct
105 Correct 89 ms 14128 KB Output is correct