Submission #385859

# Submission time Handle Problem Language Result Execution time Memory
385859 2021-04-05T06:44:44 Z i_am_noob Connecting Supertrees (IOI20_supertrees) C++17
100 / 100
297 ms 24324 KB
#include<bits/stdc++.h>
#include "supertrees.h"
using namespace std;

#define ll long long
//#define int ll
#define rep(n) rep1(i,n)
#define rep1(i,n) rep2(i,0,n)
#define rep2(i,a,b) for(int i=a; i<(b); ++i)
#define rep3(i,a,b) for(int i=a; i>=(b); --i)
#define pb push_back
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define inf 0x3f3f3f3f3f3f3f3f
#define pow2(x) (1ll<<(x))

#ifdef i_am_noob
#define bug(...) cerr << "#" << __LINE__ << " " << #__VA_ARGS__ << "- ", _do(__VA_ARGS__)
template<typename T> void _do(T x){cerr << x << endl;}
template<typename T, typename ...S> void _do(T x, S... y){cerr << x << ", ";_do(y...);}
#else
#define bug(...) 49
#endif

const int maxn=1005;

struct dsu{
    int par[maxn];
    dsu(){rep(maxn) par[i]=i;}
    int Find(int x){return x==par[x]?x:par[x]=Find(par[x]);}
    void Union(int x, int y){
        x=Find(x),y=Find(y);
        if(x==y) return;
        par[x]=y;
    }
};

int construct(vector<vector<int>> p){
	int n=sz(p);
    vector<vector<int>> res;
    res.resize(n);
    rep(n) res[i].resize(n);
    dsu d1,d2;
    rep(n) rep1(j,n) if(p[i][j]) d1.Union(i,j);
    rep(n) rep1(j,n) if(!p[i][j]) if(d1.Find(i)==d1.Find(j)) return 0;
    rep(n) rep1(j,n) if(p[i][j]==3) return 0;
    vector<int> vec[maxn],vec1[maxn];
    rep(n) vec[d1.Find(i)].pb(i);
    auto make_edge=[&](int u, int v){
        res[u][v]=res[v][u]=1;
        return;
    };
    rep(n) if(sz(vec[i])>1){
        for(auto j: vec[i]) for(auto k: vec[i]) if(p[j][k]==1) d2.Union(j,k);
        for(auto j: vec[i]) for(auto k: vec[i]) if(p[j][k]!=1) if(d2.Find(j)==d2.Find(k)) return 0;
        for(auto j: vec[i]) vec1[j].clear();
        for(auto j: vec[i]) vec1[d2.Find(j)].pb(j);
        for(auto j: vec[i]) rep1(k,sz(vec1[j])-1) make_edge(vec1[j][k],vec1[j][k+1]);
        vector<int> tmp;
        for(auto j: vec[i]) if(sz(vec1[j])) tmp.pb(j);
        if(sz(tmp)==2){
            int x,y;
            if(sz(vec1[tmp[0]])>1) x=tmp[0],y=tmp[1];
            else if(sz(vec1[tmp[1]])>1) x=tmp[1],y=tmp[0];
            else return 0;
            make_edge(vec1[x][0],vec1[y][0]);
            make_edge(vec1[x][1],vec1[y][0]);
        }
        else if(sz(tmp)>=3){
            rep1(j,sz(tmp)-1) make_edge(vec1[tmp[j]][0],vec1[tmp[j+1]][0]);
            make_edge(vec1[tmp[0]][0],vec1[tmp.back()][0]);
        }
    }
    build(res);
    return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 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 16 ms 1388 KB Output is correct
7 Correct 261 ms 24172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 16 ms 1388 KB Output is correct
7 Correct 261 ms 24172 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 11 ms 1388 KB Output is correct
13 Correct 246 ms 23660 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 6 ms 876 KB Output is correct
17 Correct 115 ms 14188 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 63 ms 6380 KB Output is correct
21 Correct 256 ms 24324 KB Output is correct
22 Correct 271 ms 24288 KB Output is correct
23 Correct 261 ms 24084 KB Output is correct
24 Correct 248 ms 24300 KB Output is correct
25 Correct 104 ms 14188 KB Output is correct
26 Correct 108 ms 14188 KB Output is correct
27 Correct 263 ms 24172 KB Output is correct
28 Correct 250 ms 24144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 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 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 11 ms 1260 KB Output is correct
9 Correct 242 ms 22124 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 11 ms 1260 KB Output is correct
13 Correct 253 ms 22380 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 6 ms 748 KB Output is correct
17 Correct 115 ms 12140 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 62 ms 5868 KB Output is correct
22 Correct 255 ms 22124 KB Output is correct
23 Correct 245 ms 22380 KB Output is correct
24 Correct 270 ms 22252 KB Output is correct
25 Correct 132 ms 12268 KB Output is correct
26 Correct 107 ms 12128 KB Output is correct
27 Correct 250 ms 22252 KB Output is correct
28 Correct 261 ms 22252 KB Output is correct
29 Correct 103 ms 12268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 62 ms 6380 KB Output is correct
5 Correct 278 ms 24144 KB Output is correct
6 Correct 251 ms 24300 KB Output is correct
7 Correct 289 ms 24200 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 70 ms 6380 KB Output is correct
10 Correct 297 ms 24300 KB Output is correct
11 Correct 260 ms 24172 KB Output is correct
12 Correct 260 ms 24172 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 63 ms 6520 KB Output is correct
17 Correct 252 ms 24172 KB Output is correct
18 Correct 281 ms 24172 KB Output is correct
19 Correct 258 ms 24172 KB Output is correct
20 Correct 246 ms 24192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 16 ms 1388 KB Output is correct
7 Correct 261 ms 24172 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 11 ms 1388 KB Output is correct
13 Correct 246 ms 23660 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 6 ms 876 KB Output is correct
17 Correct 115 ms 14188 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 63 ms 6380 KB Output is correct
21 Correct 256 ms 24324 KB Output is correct
22 Correct 271 ms 24288 KB Output is correct
23 Correct 261 ms 24084 KB Output is correct
24 Correct 248 ms 24300 KB Output is correct
25 Correct 104 ms 14188 KB Output is correct
26 Correct 108 ms 14188 KB Output is correct
27 Correct 263 ms 24172 KB Output is correct
28 Correct 250 ms 24144 KB Output is correct
29 Correct 2 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 1 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 11 ms 1260 KB Output is correct
37 Correct 242 ms 22124 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 11 ms 1260 KB Output is correct
41 Correct 253 ms 22380 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 6 ms 748 KB Output is correct
45 Correct 115 ms 12140 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 62 ms 5868 KB Output is correct
50 Correct 255 ms 22124 KB Output is correct
51 Correct 245 ms 22380 KB Output is correct
52 Correct 270 ms 22252 KB Output is correct
53 Correct 132 ms 12268 KB Output is correct
54 Correct 107 ms 12128 KB Output is correct
55 Correct 250 ms 22252 KB Output is correct
56 Correct 261 ms 22252 KB Output is correct
57 Correct 103 ms 12268 KB Output is correct
58 Correct 1 ms 364 KB Output is correct
59 Correct 1 ms 364 KB Output is correct
60 Correct 6 ms 876 KB Output is correct
61 Correct 113 ms 14188 KB Output is correct
62 Correct 1 ms 364 KB Output is correct
63 Correct 2 ms 364 KB Output is correct
64 Correct 1 ms 364 KB Output is correct
65 Correct 63 ms 6380 KB Output is correct
66 Correct 111 ms 14188 KB Output is correct
67 Correct 116 ms 14188 KB Output is correct
68 Correct 102 ms 14188 KB Output is correct
69 Correct 105 ms 14188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 16 ms 1388 KB Output is correct
7 Correct 261 ms 24172 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 11 ms 1388 KB Output is correct
13 Correct 246 ms 23660 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 6 ms 876 KB Output is correct
17 Correct 115 ms 14188 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 63 ms 6380 KB Output is correct
21 Correct 256 ms 24324 KB Output is correct
22 Correct 271 ms 24288 KB Output is correct
23 Correct 261 ms 24084 KB Output is correct
24 Correct 248 ms 24300 KB Output is correct
25 Correct 104 ms 14188 KB Output is correct
26 Correct 108 ms 14188 KB Output is correct
27 Correct 263 ms 24172 KB Output is correct
28 Correct 250 ms 24144 KB Output is correct
29 Correct 2 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 1 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 11 ms 1260 KB Output is correct
37 Correct 242 ms 22124 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 11 ms 1260 KB Output is correct
41 Correct 253 ms 22380 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 6 ms 748 KB Output is correct
45 Correct 115 ms 12140 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 62 ms 5868 KB Output is correct
50 Correct 255 ms 22124 KB Output is correct
51 Correct 245 ms 22380 KB Output is correct
52 Correct 270 ms 22252 KB Output is correct
53 Correct 132 ms 12268 KB Output is correct
54 Correct 107 ms 12128 KB Output is correct
55 Correct 250 ms 22252 KB Output is correct
56 Correct 261 ms 22252 KB Output is correct
57 Correct 103 ms 12268 KB Output is correct
58 Correct 1 ms 364 KB Output is correct
59 Correct 2 ms 364 KB Output is correct
60 Correct 1 ms 364 KB Output is correct
61 Correct 62 ms 6380 KB Output is correct
62 Correct 278 ms 24144 KB Output is correct
63 Correct 251 ms 24300 KB Output is correct
64 Correct 289 ms 24200 KB Output is correct
65 Correct 1 ms 364 KB Output is correct
66 Correct 70 ms 6380 KB Output is correct
67 Correct 297 ms 24300 KB Output is correct
68 Correct 260 ms 24172 KB Output is correct
69 Correct 260 ms 24172 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 63 ms 6520 KB Output is correct
74 Correct 252 ms 24172 KB Output is correct
75 Correct 281 ms 24172 KB Output is correct
76 Correct 258 ms 24172 KB Output is correct
77 Correct 246 ms 24192 KB Output is correct
78 Correct 1 ms 364 KB Output is correct
79 Correct 1 ms 364 KB Output is correct
80 Correct 6 ms 876 KB Output is correct
81 Correct 113 ms 14188 KB Output is correct
82 Correct 1 ms 364 KB Output is correct
83 Correct 2 ms 364 KB Output is correct
84 Correct 1 ms 364 KB Output is correct
85 Correct 63 ms 6380 KB Output is correct
86 Correct 111 ms 14188 KB Output is correct
87 Correct 116 ms 14188 KB Output is correct
88 Correct 102 ms 14188 KB Output is correct
89 Correct 105 ms 14188 KB Output is correct
90 Correct 1 ms 364 KB Output is correct
91 Correct 1 ms 364 KB Output is correct
92 Correct 6 ms 876 KB Output is correct
93 Correct 114 ms 14188 KB Output is correct
94 Correct 1 ms 364 KB Output is correct
95 Correct 1 ms 364 KB Output is correct
96 Correct 1 ms 364 KB Output is correct
97 Correct 26 ms 3840 KB Output is correct
98 Correct 107 ms 14188 KB Output is correct
99 Correct 108 ms 14188 KB Output is correct
100 Correct 102 ms 14188 KB Output is correct
101 Correct 112 ms 14188 KB Output is correct
102 Correct 113 ms 14188 KB Output is correct
103 Correct 110 ms 14188 KB Output is correct
104 Correct 112 ms 14188 KB Output is correct
105 Correct 116 ms 14188 KB Output is correct