Submission #442008

# Submission time Handle Problem Language Result Execution time Memory
442008 2021-07-06T17:45:07 Z julian33 Connecting Supertrees (IOI20_supertrees) C++14
100 / 100
260 ms 26052 KB
#include <bits/stdc++.h>
#include "supertrees.h"
 
using namespace std;
 
#ifdef LOCAL
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values) {
    cerr<<vars<<" = ";
    string delim="";
    (...,(cerr<<delim<<values,delim=", "));
    cerr<<"\n";
}
#else
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values) {}
#endif
 
#define FOR(i,j,n) for(int i=j;i<n;i++)
 
#define pb push_back
#define sz(x) (int)(x.size())
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> inline void maxa(T& a,T b){a=max(a,b);}
template<typename T> inline void mina(T& a,T b){a=min(a,b);} 
 
// void build(vector<vector<int>> b){
//     int n=sz(b); 
//     for(int i=0;i<n;i++){
//         for(int j=0;j<n;j++){
//             cout<<b[i][j]<<" ";
//         }
//         cout<<"\n";
//     }
// }
 
const int mxN=1e3+5;
 
int uf[mxN],seen[mxN];
vector<int> component[mxN];
vector<vector<int>> g;
 
int find(int x){return uf[x]<0?x:uf[x]=find(uf[x]);}
bool same(int x,int y){return find(x)==find(y);}
void unite(int x,int y){
    x=find(x); y=find(y);
    if(x==y)
        return;
    if(uf[x]>uf[y])
        swap(x,y);
    uf[x]+=uf[y]; uf[y]=x;
}
 
int construct(vector<vector<int>> p){
    g=p;
    memset(uf,-1,sizeof(uf));
    int n=sz(p);
    vector<vector<int>> b;
    b.resize(n);
    for(auto &u:b)
        u.resize(n);
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(g[i][j]==3)
                return 0;
            if(g[i][j]){
                unite(i,j);
            }
        }
    }
    for(int i=0;i<n;i++){
        component[find(i)].pb(i);
        for(int j=0;j<n;j++){
            if(!g[i][j] && same(i,j))
                return 0;
        }
    }
    for(int i=0;i<n;i++){
        if(sz(component[i])<=1)
            continue;
        vector<vector<int>> line; vector<int> ring;
        for(int &j:component[i]){
            if(seen[j])
                continue;
            vector<int> one={j};
            for(int k=0;k<n;k++){
                if(g[j][k]==1 && j!=k){
                    one.pb(k);
                    seen[k]=1;
                }
            }
            if(sz(one)==1)
                ring.pb(j);
            else
                line.pb(one);
        }
        if(sz(line)==0){
            if(sz(ring)==2)
                return 0;
            for(int j=0;j<sz(ring);j++){
                b[ring[j]][ring[(j+1)%sz(ring)]]=b[ring[(j+1)%sz(ring)]][ring[j]]=1;
            }
        } else{
            for(int j=0;j<sz(ring)-1;j++){
                b[ring[j]][ring[j+1]]=b[ring[j+1]][ring[j]]=1;
            }
            for(auto u:line){
                for(int j=0;j<sz(u)-1;j++){
                    b[u[j]][u[j+1]]=b[u[j+1]][u[j]]=1;
                }
            }
            for(int j=0;j<sz(line)-1;j++){
                b[line[j][0]][line[j+1][0]]=b[line[j+1][0]][line[j][0]]=1;
            }
            if(sz(ring)){
                b[line.back()[0]][ring.back()]=b[ring.back()][line.back()[0]]=1;
                b[line[0][0]][ring[0]]=b[ring[0]][line[0][0]]=1;
            } else if(sz(line)>1){
                b[line.back()[0]][line[0][0]]=b[line[0][0]][line.back()[0]]=1;
            }
        }
    }
    build(b);
    return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 252 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 10 ms 1356 KB Output is correct
7 Correct 230 ms 26020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 252 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 10 ms 1356 KB Output is correct
7 Correct 230 ms 26020 KB Output is correct
8 Correct 0 ms 328 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 10 ms 1348 KB Output is correct
13 Correct 236 ms 25988 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 5 ms 948 KB Output is correct
17 Correct 111 ms 16152 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 61 ms 6684 KB Output is correct
21 Correct 240 ms 26052 KB Output is correct
22 Correct 238 ms 25924 KB Output is correct
23 Correct 252 ms 26008 KB Output is correct
24 Correct 236 ms 26004 KB Output is correct
25 Correct 106 ms 16020 KB Output is correct
26 Correct 96 ms 16036 KB Output is correct
27 Correct 250 ms 26004 KB Output is correct
28 Correct 230 ms 26008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 10 ms 1356 KB Output is correct
9 Correct 229 ms 26024 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 10 ms 1356 KB Output is correct
13 Correct 234 ms 25956 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 5 ms 860 KB Output is correct
17 Correct 112 ms 16040 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 61 ms 6724 KB Output is correct
22 Correct 243 ms 26008 KB Output is correct
23 Correct 243 ms 26052 KB Output is correct
24 Correct 257 ms 25984 KB Output is correct
25 Correct 99 ms 16068 KB Output is correct
26 Correct 99 ms 16028 KB Output is correct
27 Correct 250 ms 26016 KB Output is correct
28 Correct 260 ms 25968 KB Output is correct
29 Correct 108 ms 16068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 59 ms 6704 KB Output is correct
5 Correct 241 ms 26016 KB Output is correct
6 Correct 235 ms 26052 KB Output is correct
7 Correct 257 ms 26004 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 62 ms 6712 KB Output is correct
10 Correct 241 ms 26020 KB Output is correct
11 Correct 241 ms 26004 KB Output is correct
12 Correct 254 ms 26020 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 60 ms 6772 KB Output is correct
17 Correct 244 ms 26016 KB Output is correct
18 Correct 239 ms 25924 KB Output is correct
19 Correct 241 ms 26004 KB Output is correct
20 Correct 235 ms 25992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 252 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 10 ms 1356 KB Output is correct
7 Correct 230 ms 26020 KB Output is correct
8 Correct 0 ms 328 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 10 ms 1348 KB Output is correct
13 Correct 236 ms 25988 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 5 ms 948 KB Output is correct
17 Correct 111 ms 16152 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 61 ms 6684 KB Output is correct
21 Correct 240 ms 26052 KB Output is correct
22 Correct 238 ms 25924 KB Output is correct
23 Correct 252 ms 26008 KB Output is correct
24 Correct 236 ms 26004 KB Output is correct
25 Correct 106 ms 16020 KB Output is correct
26 Correct 96 ms 16036 KB Output is correct
27 Correct 250 ms 26004 KB Output is correct
28 Correct 230 ms 26008 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 0 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 10 ms 1356 KB Output is correct
37 Correct 229 ms 26024 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 10 ms 1356 KB Output is correct
41 Correct 234 ms 25956 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 0 ms 204 KB Output is correct
44 Correct 5 ms 860 KB Output is correct
45 Correct 112 ms 16040 KB Output is correct
46 Correct 0 ms 204 KB Output is correct
47 Correct 0 ms 204 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 61 ms 6724 KB Output is correct
50 Correct 243 ms 26008 KB Output is correct
51 Correct 243 ms 26052 KB Output is correct
52 Correct 257 ms 25984 KB Output is correct
53 Correct 99 ms 16068 KB Output is correct
54 Correct 99 ms 16028 KB Output is correct
55 Correct 250 ms 26016 KB Output is correct
56 Correct 260 ms 25968 KB Output is correct
57 Correct 108 ms 16068 KB Output is correct
58 Correct 0 ms 204 KB Output is correct
59 Correct 0 ms 204 KB Output is correct
60 Correct 5 ms 860 KB Output is correct
61 Correct 108 ms 16068 KB Output is correct
62 Correct 1 ms 204 KB Output is correct
63 Correct 0 ms 204 KB Output is correct
64 Correct 0 ms 204 KB Output is correct
65 Correct 63 ms 6668 KB Output is correct
66 Correct 103 ms 16020 KB Output is correct
67 Correct 99 ms 16036 KB Output is correct
68 Correct 97 ms 16068 KB Output is correct
69 Correct 106 ms 16036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 252 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 10 ms 1356 KB Output is correct
7 Correct 230 ms 26020 KB Output is correct
8 Correct 0 ms 328 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 10 ms 1348 KB Output is correct
13 Correct 236 ms 25988 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 5 ms 948 KB Output is correct
17 Correct 111 ms 16152 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 61 ms 6684 KB Output is correct
21 Correct 240 ms 26052 KB Output is correct
22 Correct 238 ms 25924 KB Output is correct
23 Correct 252 ms 26008 KB Output is correct
24 Correct 236 ms 26004 KB Output is correct
25 Correct 106 ms 16020 KB Output is correct
26 Correct 96 ms 16036 KB Output is correct
27 Correct 250 ms 26004 KB Output is correct
28 Correct 230 ms 26008 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 0 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 10 ms 1356 KB Output is correct
37 Correct 229 ms 26024 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 10 ms 1356 KB Output is correct
41 Correct 234 ms 25956 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 0 ms 204 KB Output is correct
44 Correct 5 ms 860 KB Output is correct
45 Correct 112 ms 16040 KB Output is correct
46 Correct 0 ms 204 KB Output is correct
47 Correct 0 ms 204 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 61 ms 6724 KB Output is correct
50 Correct 243 ms 26008 KB Output is correct
51 Correct 243 ms 26052 KB Output is correct
52 Correct 257 ms 25984 KB Output is correct
53 Correct 99 ms 16068 KB Output is correct
54 Correct 99 ms 16028 KB Output is correct
55 Correct 250 ms 26016 KB Output is correct
56 Correct 260 ms 25968 KB Output is correct
57 Correct 108 ms 16068 KB Output is correct
58 Correct 1 ms 204 KB Output is correct
59 Correct 1 ms 204 KB Output is correct
60 Correct 0 ms 204 KB Output is correct
61 Correct 59 ms 6704 KB Output is correct
62 Correct 241 ms 26016 KB Output is correct
63 Correct 235 ms 26052 KB Output is correct
64 Correct 257 ms 26004 KB Output is correct
65 Correct 1 ms 204 KB Output is correct
66 Correct 62 ms 6712 KB Output is correct
67 Correct 241 ms 26020 KB Output is correct
68 Correct 241 ms 26004 KB Output is correct
69 Correct 254 ms 26020 KB Output is correct
70 Correct 1 ms 204 KB Output is correct
71 Correct 1 ms 204 KB Output is correct
72 Correct 1 ms 204 KB Output is correct
73 Correct 60 ms 6772 KB Output is correct
74 Correct 244 ms 26016 KB Output is correct
75 Correct 239 ms 25924 KB Output is correct
76 Correct 241 ms 26004 KB Output is correct
77 Correct 235 ms 25992 KB Output is correct
78 Correct 0 ms 204 KB Output is correct
79 Correct 0 ms 204 KB Output is correct
80 Correct 5 ms 860 KB Output is correct
81 Correct 108 ms 16068 KB Output is correct
82 Correct 1 ms 204 KB Output is correct
83 Correct 0 ms 204 KB Output is correct
84 Correct 0 ms 204 KB Output is correct
85 Correct 63 ms 6668 KB Output is correct
86 Correct 103 ms 16020 KB Output is correct
87 Correct 99 ms 16036 KB Output is correct
88 Correct 97 ms 16068 KB Output is correct
89 Correct 106 ms 16036 KB Output is correct
90 Correct 1 ms 204 KB Output is correct
91 Correct 1 ms 204 KB Output is correct
92 Correct 5 ms 868 KB Output is correct
93 Correct 101 ms 16036 KB Output is correct
94 Correct 0 ms 204 KB Output is correct
95 Correct 1 ms 204 KB Output is correct
96 Correct 0 ms 204 KB Output is correct
97 Correct 27 ms 4252 KB Output is correct
98 Correct 96 ms 16068 KB Output is correct
99 Correct 95 ms 16020 KB Output is correct
100 Correct 96 ms 16028 KB Output is correct
101 Correct 98 ms 16032 KB Output is correct
102 Correct 95 ms 16068 KB Output is correct
103 Correct 95 ms 18056 KB Output is correct
104 Correct 94 ms 18056 KB Output is correct
105 Correct 103 ms 17940 KB Output is correct