Submission #578051

# Submission time Handle Problem Language Result Execution time Memory
578051 2022-06-15T20:52:14 Z perchuts Connecting Supertrees (IOI20_supertrees) C++17
100 / 100
322 ms 69052 KB
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define endl '\n'
#define pb push_back
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include "supertrees.h"

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ii = pair<int,int>;
using iii = tuple<int,int,int>;

const int inf = 2e9+1;
const int mod = 1e9+7;
const int maxn = 1e5+100;

template<typename X, typename Y> bool ckmin(X& x, const Y& y) { return (y < x) ? (x=y,1):0; }
template<typename X, typename Y> bool ckmax(X& x, const Y& y) { return (x < y) ? (x=y,1):0; }

set<int>tree[1001];
bool vis[1001];
int pai[1001];

// void build(vector<vector<int>>b){
//     vector<ii>edges;
//     int n = sz(b[0]);
//     for(int i=0;i<n;++i){
//         for(int j=i+1;j<n;++j){
//             if(b[i][j])edges.pb({i,j});
//         }
//     }
//     for(auto [x,y]:edges)cout<<x<<" "<<y<<endl;
// }

int construct(vector<vector<int>>v){
    int n = sz(v[0]);
    for(int i=0;i<n;++i){
        for(int j=0;j<n;++j){
            if(v[i][j]>2)return 0;//impossivel se v[i][j] == 3
            if(v[i][j]==1)tree[i].insert(j);//mesma arvore
        }
        assert(tree[i].count(i));//enunciado nao deixou isso claro
    }

    vector<vector<int>>ans(n,vector<int>(n));
    for(int i=0;i<n;++i){
        if(!vis[i]){
            vis[i] = 1, pai[i] = i;
            for(auto x:tree[i]){
                if(x==i)continue;
                vis[x] = 1, pai[x] = i, ans[i][x] = ans[x][i] = 1;
                if(tree[x]!=tree[i])return 0;
            }
        }
    }

    //as arvores estao todas certas!

    for(int i=0;i<n;++i)vis[i] = 0;

    for(int i=0;i<n;++i){
        if(vis[pai[i]])continue;
        int x = pai[i];
        vis[x] = 1;
        set<int>ciclo={x};
        for(int j=0;j<n;++j)if(v[x][pai[j]]==2)ciclo.insert(pai[j]);
        int ultimo = *ciclo.rbegin();
        if(sz(ciclo)==1)continue;//nao tem ciclo
        if(sz(ciclo)==2)return 0;//nao existe ciclo de tamanho 2
        for(auto y:ciclo){
            ans[ultimo][y] = ans[y][ultimo] = 1, vis[y] = 1, ultimo = y;
            for(int j=0;j<n;++j){
                if(pai[j]==y)continue;
                if(ciclo.count(pai[j])==0){
                    if(v[y][j]!=0)return 0;
                }else{
                    if(v[y][j]!=2)return 0;
                }
            }
        }
    }

    build(ans);

    return 1;
}

// int main(){
//     int n;cin>>n;
//     vector<vector<int>>v(n,vector<int>(n));
//     for(int i=0;i<n;++i)for(int j=0;j<n;++j)cin>>v[i][j];
//     cout<<construct(v)<<endl;
// }
# Verdict Execution time Memory Grader output
1 Correct 1 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 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 13 ms 3040 KB Output is correct
7 Correct 322 ms 69052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 13 ms 3040 KB Output is correct
7 Correct 322 ms 69052 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 8 ms 1236 KB Output is correct
13 Correct 175 ms 22072 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 6 ms 1748 KB Output is correct
17 Correct 145 ms 35672 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 45 ms 6092 KB Output is correct
21 Correct 199 ms 26820 KB Output is correct
22 Correct 176 ms 22148 KB Output is correct
23 Correct 280 ms 45500 KB Output is correct
24 Correct 193 ms 22192 KB Output is correct
25 Correct 174 ms 16920 KB Output is correct
26 Correct 71 ms 12216 KB Output is correct
27 Correct 252 ms 45512 KB Output is correct
28 Correct 215 ms 22192 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 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 9 ms 1236 KB Output is correct
9 Correct 214 ms 22020 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 9 ms 1236 KB Output is correct
13 Correct 220 ms 24012 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 80 ms 14128 KB Output is correct
18 Correct 1 ms 352 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 47 ms 6316 KB Output is correct
22 Correct 206 ms 24100 KB Output is correct
23 Correct 188 ms 24088 KB Output is correct
24 Correct 222 ms 24036 KB Output is correct
25 Correct 77 ms 14260 KB Output is correct
26 Correct 77 ms 14116 KB Output is correct
27 Correct 225 ms 24048 KB Output is correct
28 Correct 215 ms 24032 KB Output is correct
29 Correct 82 ms 14116 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 56 ms 6068 KB Output is correct
5 Correct 185 ms 26828 KB Output is correct
6 Correct 183 ms 22152 KB Output is correct
7 Correct 257 ms 45540 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 48 ms 6220 KB Output is correct
10 Correct 219 ms 24000 KB Output is correct
11 Correct 206 ms 24000 KB Output is correct
12 Correct 228 ms 24032 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 47 ms 6228 KB Output is correct
17 Correct 199 ms 24044 KB Output is correct
18 Correct 203 ms 24372 KB Output is correct
19 Correct 189 ms 24668 KB Output is correct
20 Correct 223 ms 24112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 13 ms 3040 KB Output is correct
7 Correct 322 ms 69052 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 8 ms 1236 KB Output is correct
13 Correct 175 ms 22072 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 6 ms 1748 KB Output is correct
17 Correct 145 ms 35672 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 45 ms 6092 KB Output is correct
21 Correct 199 ms 26820 KB Output is correct
22 Correct 176 ms 22148 KB Output is correct
23 Correct 280 ms 45500 KB Output is correct
24 Correct 193 ms 22192 KB Output is correct
25 Correct 174 ms 16920 KB Output is correct
26 Correct 71 ms 12216 KB Output is correct
27 Correct 252 ms 45512 KB Output is correct
28 Correct 215 ms 22192 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 9 ms 1236 KB Output is correct
37 Correct 214 ms 22020 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 9 ms 1236 KB Output is correct
41 Correct 220 ms 24012 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 4 ms 852 KB Output is correct
45 Correct 80 ms 14128 KB Output is correct
46 Correct 1 ms 352 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 47 ms 6316 KB Output is correct
50 Correct 206 ms 24100 KB Output is correct
51 Correct 188 ms 24088 KB Output is correct
52 Correct 222 ms 24036 KB Output is correct
53 Correct 77 ms 14260 KB Output is correct
54 Correct 77 ms 14116 KB Output is correct
55 Correct 225 ms 24048 KB Output is correct
56 Correct 215 ms 24032 KB Output is correct
57 Correct 82 ms 14116 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 5 ms 1512 KB Output is correct
61 Correct 120 ms 29836 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 352 KB Output is correct
65 Correct 57 ms 6280 KB Output is correct
66 Correct 77 ms 14116 KB Output is correct
67 Correct 74 ms 14244 KB Output is correct
68 Correct 78 ms 14640 KB Output is correct
69 Correct 75 ms 14120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 13 ms 3040 KB Output is correct
7 Correct 322 ms 69052 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 8 ms 1236 KB Output is correct
13 Correct 175 ms 22072 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 6 ms 1748 KB Output is correct
17 Correct 145 ms 35672 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 45 ms 6092 KB Output is correct
21 Correct 199 ms 26820 KB Output is correct
22 Correct 176 ms 22148 KB Output is correct
23 Correct 280 ms 45500 KB Output is correct
24 Correct 193 ms 22192 KB Output is correct
25 Correct 174 ms 16920 KB Output is correct
26 Correct 71 ms 12216 KB Output is correct
27 Correct 252 ms 45512 KB Output is correct
28 Correct 215 ms 22192 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 9 ms 1236 KB Output is correct
37 Correct 214 ms 22020 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 9 ms 1236 KB Output is correct
41 Correct 220 ms 24012 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 4 ms 852 KB Output is correct
45 Correct 80 ms 14128 KB Output is correct
46 Correct 1 ms 352 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 47 ms 6316 KB Output is correct
50 Correct 206 ms 24100 KB Output is correct
51 Correct 188 ms 24088 KB Output is correct
52 Correct 222 ms 24036 KB Output is correct
53 Correct 77 ms 14260 KB Output is correct
54 Correct 77 ms 14116 KB Output is correct
55 Correct 225 ms 24048 KB Output is correct
56 Correct 215 ms 24032 KB Output is correct
57 Correct 82 ms 14116 KB Output is correct
58 Correct 0 ms 340 KB Output is correct
59 Correct 0 ms 340 KB Output is correct
60 Correct 0 ms 340 KB Output is correct
61 Correct 56 ms 6068 KB Output is correct
62 Correct 185 ms 26828 KB Output is correct
63 Correct 183 ms 22152 KB Output is correct
64 Correct 257 ms 45540 KB Output is correct
65 Correct 0 ms 340 KB Output is correct
66 Correct 48 ms 6220 KB Output is correct
67 Correct 219 ms 24000 KB Output is correct
68 Correct 206 ms 24000 KB Output is correct
69 Correct 228 ms 24032 KB Output is correct
70 Correct 1 ms 348 KB Output is correct
71 Correct 1 ms 348 KB Output is correct
72 Correct 1 ms 340 KB Output is correct
73 Correct 47 ms 6228 KB Output is correct
74 Correct 199 ms 24044 KB Output is correct
75 Correct 203 ms 24372 KB Output is correct
76 Correct 189 ms 24668 KB Output is correct
77 Correct 223 ms 24112 KB Output is correct
78 Correct 1 ms 340 KB Output is correct
79 Correct 1 ms 348 KB Output is correct
80 Correct 5 ms 1512 KB Output is correct
81 Correct 120 ms 29836 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 352 KB Output is correct
85 Correct 57 ms 6280 KB Output is correct
86 Correct 77 ms 14116 KB Output is correct
87 Correct 74 ms 14244 KB Output is correct
88 Correct 78 ms 14640 KB Output is correct
89 Correct 75 ms 14120 KB Output is correct
90 Correct 1 ms 352 KB Output is correct
91 Correct 1 ms 352 KB Output is correct
92 Correct 4 ms 724 KB Output is correct
93 Correct 77 ms 10168 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 356 KB Output is correct
97 Correct 19 ms 2796 KB Output is correct
98 Correct 72 ms 10156 KB Output is correct
99 Correct 81 ms 10152 KB Output is correct
100 Correct 76 ms 10148 KB Output is correct
101 Correct 69 ms 10152 KB Output is correct
102 Correct 63 ms 10152 KB Output is correct
103 Correct 67 ms 10084 KB Output is correct
104 Correct 68 ms 10080 KB Output is correct
105 Correct 87 ms 10164 KB Output is correct