Submission #623127

# Submission time Handle Problem Language Result Execution time Memory
623127 2022-08-05T08:37:03 Z PanTkd Connecting Supertrees (IOI20_supertrees) C++14
100 / 100
365 ms 23988 KB
//
//  main.cpp
//
//  Created by Panagiotis Chadjicostas on
//  Copyright © Panagiotis Hadjicostas. All rights reserved.
//
#include "supertrees.h"

#include <iostream>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iterator>
#include <limits>
#include <list>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <unordered_map>

using namespace std;

typedef int ll;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
#define fo(i,a,b) for(int i = a; i<=b; i++)
#define f(i,b) for(int i=0;i<b;i++)
#define F first
#define S second
#define sz size
#define ls s,m,idx<<1
#define rs m+1,e,idx<<1|1
const ll MOD=ll(1e9)+7;
const ll MAXN=2*ll(1e6);
void checker(){
    ll n=rand()%20+2;
    vi a(n,ll());
    for(ll i=0;i<n;i++){
        a[i]=rand()%20+2;
    }
    for(ll b=0;b<(1<<n);b++){
        vi on,off;
        for(ll i=0;i<n;i++){
            if(i&(1<<i)){
                on.push_back(i);
            }
            else{
                off.push_back(i);
            }
        }
    }
}
///////////////////////////////////////////////////////////////////////
void build(vector<vector<ll> > b);
vi parent ;
int find(int x){
    if(parent[x]==x)
        return x;
    parent[x]=find(parent[x]);
    return parent[x];
}
void onion(int x, int y){
    parent[find(y)]=find(x);
    return;
}
vector<vi> A,B;
vi V;
void dfs(ll p,ll s){
    B[p].push_back(s);
    V[s]=1;
    for(auto x:A[s])
        if(!V[x])
            dfs(p,x);
}
int construct(vector<vector<ll> > p)
{
    ll s=0;
    ll n=p.size();
    vector<vector<ll> > ans (n, vector<int>(n, 0));
    parent.assign(n,0);
    for(ll i=0;i<n;i++)
        parent[i]=i;
    
    for(ll i=0;i<n;i++){
        for(ll j=i+1;j<n;j++){
            
            if(p[i][j]==1&&find(i)!=find(j)){
                ans[i][j]=ans[j][i]=1;
                onion(i,j);
            }
            else if (p[i][j] == 3) return 0;
        }
    }

    for(ll i=0;i<n;i++){
        vi v;
        v.push_back(parent[i]);

        for(ll j=i+1;j<n;j++){
            if(p[i][j]==2&&find(i)!=find(j)){
                v.push_back(parent[j]);
                onion(i,j);
            }
        }

        if(v.size()==2)return 0;

        for(ll k=0;k<v.size()-1;k++){
            ans[v[k]][v[k+1]]=1;
            ans[v[k+1]][v[k]]=1;
        }
        ans[v[0]][v[v.size()-1]]=ans[v[v.size()-1]][v[0]]=1;
    }
    for(ll i=0;i<n;i++){
        ans[i][i]=0;
        for(ll j=i+1;j<n;j++){
            if (p[i][j] == 0 && find(i) == find(j)) return 0;
            for(ll k=j+1;k<n;k++)
                if(p[i][j]==1&&p[j][k]==1&&p[i][k]!=1)return 0;
        } 
    }
    build(ans);
    return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:115:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  115 |         for(ll k=0;k<v.size()-1;k++){
      |                    ~^~~~~~~~~~~
supertrees.cpp:84:8: warning: unused variable 's' [-Wunused-variable]
   84 |     ll s=0;
      |        ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1124 KB Output is correct
7 Correct 283 ms 22020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1124 KB Output is correct
7 Correct 283 ms 22020 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1108 KB Output is correct
13 Correct 228 ms 22096 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 712 KB Output is correct
17 Correct 80 ms 12036 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 52 ms 5716 KB Output is correct
21 Correct 246 ms 22032 KB Output is correct
22 Correct 223 ms 21936 KB Output is correct
23 Correct 347 ms 22120 KB Output is correct
24 Correct 231 ms 22040 KB Output is correct
25 Correct 84 ms 12048 KB Output is correct
26 Correct 75 ms 12032 KB Output is correct
27 Correct 365 ms 23984 KB Output is correct
28 Correct 249 ms 23988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 7 ms 1108 KB Output is correct
9 Correct 237 ms 22044 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 8 ms 1108 KB Output is correct
13 Correct 241 ms 22032 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 90 ms 12040 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 48 ms 5772 KB Output is correct
22 Correct 219 ms 21956 KB Output is correct
23 Correct 217 ms 21964 KB Output is correct
24 Correct 242 ms 22020 KB Output is correct
25 Correct 69 ms 12032 KB Output is correct
26 Correct 68 ms 12036 KB Output is correct
27 Correct 234 ms 21928 KB Output is correct
28 Correct 238 ms 22020 KB Output is correct
29 Correct 79 ms 12108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 49 ms 5708 KB Output is correct
5 Correct 263 ms 22012 KB Output is correct
6 Correct 230 ms 21956 KB Output is correct
7 Correct 357 ms 22032 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 59 ms 5704 KB Output is correct
10 Correct 232 ms 22020 KB Output is correct
11 Correct 238 ms 22060 KB Output is correct
12 Correct 232 ms 22000 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 52 ms 5752 KB Output is correct
17 Correct 225 ms 22040 KB Output is correct
18 Correct 243 ms 21988 KB Output is correct
19 Correct 223 ms 21964 KB Output is correct
20 Correct 221 ms 22016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1124 KB Output is correct
7 Correct 283 ms 22020 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1108 KB Output is correct
13 Correct 228 ms 22096 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 712 KB Output is correct
17 Correct 80 ms 12036 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 52 ms 5716 KB Output is correct
21 Correct 246 ms 22032 KB Output is correct
22 Correct 223 ms 21936 KB Output is correct
23 Correct 347 ms 22120 KB Output is correct
24 Correct 231 ms 22040 KB Output is correct
25 Correct 84 ms 12048 KB Output is correct
26 Correct 75 ms 12032 KB Output is correct
27 Correct 365 ms 23984 KB Output is correct
28 Correct 249 ms 23988 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 7 ms 1108 KB Output is correct
37 Correct 237 ms 22044 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 8 ms 1108 KB Output is correct
41 Correct 241 ms 22032 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 3 ms 724 KB Output is correct
45 Correct 90 ms 12040 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 48 ms 5772 KB Output is correct
50 Correct 219 ms 21956 KB Output is correct
51 Correct 217 ms 21964 KB Output is correct
52 Correct 242 ms 22020 KB Output is correct
53 Correct 69 ms 12032 KB Output is correct
54 Correct 68 ms 12036 KB Output is correct
55 Correct 234 ms 21928 KB Output is correct
56 Correct 238 ms 22020 KB Output is correct
57 Correct 79 ms 12108 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 4 ms 852 KB Output is correct
61 Correct 79 ms 14068 KB Output is correct
62 Correct 0 ms 304 KB Output is correct
63 Correct 1 ms 212 KB Output is correct
64 Correct 0 ms 212 KB Output is correct
65 Correct 57 ms 6200 KB Output is correct
66 Correct 75 ms 14072 KB Output is correct
67 Correct 70 ms 14028 KB Output is correct
68 Correct 68 ms 14076 KB Output is correct
69 Correct 66 ms 14072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1124 KB Output is correct
7 Correct 283 ms 22020 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1108 KB Output is correct
13 Correct 228 ms 22096 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 712 KB Output is correct
17 Correct 80 ms 12036 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 52 ms 5716 KB Output is correct
21 Correct 246 ms 22032 KB Output is correct
22 Correct 223 ms 21936 KB Output is correct
23 Correct 347 ms 22120 KB Output is correct
24 Correct 231 ms 22040 KB Output is correct
25 Correct 84 ms 12048 KB Output is correct
26 Correct 75 ms 12032 KB Output is correct
27 Correct 365 ms 23984 KB Output is correct
28 Correct 249 ms 23988 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 7 ms 1108 KB Output is correct
37 Correct 237 ms 22044 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 8 ms 1108 KB Output is correct
41 Correct 241 ms 22032 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 3 ms 724 KB Output is correct
45 Correct 90 ms 12040 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 48 ms 5772 KB Output is correct
50 Correct 219 ms 21956 KB Output is correct
51 Correct 217 ms 21964 KB Output is correct
52 Correct 242 ms 22020 KB Output is correct
53 Correct 69 ms 12032 KB Output is correct
54 Correct 68 ms 12036 KB Output is correct
55 Correct 234 ms 21928 KB Output is correct
56 Correct 238 ms 22020 KB Output is correct
57 Correct 79 ms 12108 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 49 ms 5708 KB Output is correct
62 Correct 263 ms 22012 KB Output is correct
63 Correct 230 ms 21956 KB Output is correct
64 Correct 357 ms 22032 KB Output is correct
65 Correct 0 ms 212 KB Output is correct
66 Correct 59 ms 5704 KB Output is correct
67 Correct 232 ms 22020 KB Output is correct
68 Correct 238 ms 22060 KB Output is correct
69 Correct 232 ms 22000 KB Output is correct
70 Correct 1 ms 212 KB Output is correct
71 Correct 0 ms 212 KB Output is correct
72 Correct 0 ms 212 KB Output is correct
73 Correct 52 ms 5752 KB Output is correct
74 Correct 225 ms 22040 KB Output is correct
75 Correct 243 ms 21988 KB Output is correct
76 Correct 223 ms 21964 KB Output is correct
77 Correct 221 ms 22016 KB Output is correct
78 Correct 0 ms 212 KB Output is correct
79 Correct 0 ms 212 KB Output is correct
80 Correct 4 ms 852 KB Output is correct
81 Correct 79 ms 14068 KB Output is correct
82 Correct 0 ms 304 KB Output is correct
83 Correct 1 ms 212 KB Output is correct
84 Correct 0 ms 212 KB Output is correct
85 Correct 57 ms 6200 KB Output is correct
86 Correct 75 ms 14072 KB Output is correct
87 Correct 70 ms 14028 KB Output is correct
88 Correct 68 ms 14076 KB Output is correct
89 Correct 66 ms 14072 KB Output is correct
90 Correct 1 ms 212 KB Output is correct
91 Correct 0 ms 300 KB Output is correct
92 Correct 3 ms 852 KB Output is correct
93 Correct 77 ms 14068 KB Output is correct
94 Correct 0 ms 300 KB Output is correct
95 Correct 0 ms 212 KB Output is correct
96 Correct 0 ms 212 KB Output is correct
97 Correct 16 ms 3768 KB Output is correct
98 Correct 78 ms 14080 KB Output is correct
99 Correct 67 ms 14076 KB Output is correct
100 Correct 65 ms 13984 KB Output is correct
101 Correct 70 ms 14076 KB Output is correct
102 Correct 64 ms 14064 KB Output is correct
103 Correct 71 ms 14072 KB Output is correct
104 Correct 68 ms 14028 KB Output is correct
105 Correct 73 ms 14068 KB Output is correct