Submission #301149

# Submission time Handle Problem Language Result Execution time Memory
301149 2020-09-17T16:57:38 Z Sho10 Connecting Supertrees (IOI20_supertrees) C++14
100 / 100
321 ms 40696 KB
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#include "supertrees.h"
#define ll long long
#define double long double
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005ll
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,a[2005][2005],ans[2005][2005],pos[2005],viz[2005];
vector<ll>v;
void dfs(ll node,ll nr){
viz[node]=1;
v.pb(node);
for(ll i=0;i<n;i++)
{
   if(viz[i]||a[node][i]>nr||a[node][i]==0){
    continue;
   }
   dfs(i,nr);
}
}
int construct(vector<vector<int>>p){
n=p[0].size();
for(ll i=0;i<n;i++)
{
    for(ll j=0;j<n;j++)
    {
        a[i][j]=p[i][j];
        if(a[i][j]==3){
            return 0;
        }
    }
}
for(ll i=0;i<n;i++)
{
    if(viz[i]){
        continue;
    }
    v.clear();
    dfs(i,1ll);
    for(auto it1 : v){
        for(auto it2: v){
            if(a[it1][it2]!=1){
                return 0;
            }
        }
    }
    for(auto it : v){
        pos[it]=v[0];
    }
    for(ll j=1;j<v.size();j++)
    {
        ans[v[j]][v[j-1]]=1;
        ans[v[j-1]][v[j]]=1;
    }

}
memset(viz,0,sizeof(viz));
for(ll i=0;i<n;i++)
{
    if(viz[i]){
        continue;
    }
    v.clear();
    dfs(i,2);
    for(auto it1 : v){
for(auto it2 : v){
    if(a[it1][it2]==0){
        return 0;
    }
}
    }
    vector<ll>x;
    for(auto it : v){
        if(pos[it]==it){
            x.pb(it);
        }
    }
    if(x.size()<=1){
        continue;
    }
    if(x.size()==2){
        return 0;
    }
    for(ll j=0;j<x.size();j++)
    {
        ll nr=x.size();
        ll s1=x[j],s2=x[(j+1)%nr];
        ans[s1][s2]=1;
        ans[s2][s1]=1;
    }
}
vector<vector<int>>res;
res.resize(n);
for(ll i=0;i<n;i++)
{
    for(ll j=0;j<n;j++)
    {
       res[i].pb(ans[i][j]);
    }
}
build(res);
return 1;
}
/*
int32_t main(){
CODE_START;
*/

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:67:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |     for(ll j=1;j<v.size();j++)
      |                ~^~~~~~~~~
supertrees.cpp:101:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |     for(ll j=0;j<x.size();j++)
      |                ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 12 ms 3200 KB Output is correct
7 Correct 266 ms 38136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 12 ms 3200 KB Output is correct
7 Correct 266 ms 38136 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 11 ms 2432 KB Output is correct
13 Correct 251 ms 34040 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 5 ms 1792 KB Output is correct
17 Correct 118 ms 20088 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 66 ms 11896 KB Output is correct
21 Correct 261 ms 38264 KB Output is correct
22 Correct 252 ms 38756 KB Output is correct
23 Correct 267 ms 38136 KB Output is correct
24 Correct 254 ms 34424 KB Output is correct
25 Correct 115 ms 22264 KB Output is correct
26 Correct 104 ms 20476 KB Output is correct
27 Correct 263 ms 38136 KB Output is correct
28 Correct 256 ms 34424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 11 ms 2432 KB Output is correct
9 Correct 251 ms 34168 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 16 ms 3200 KB Output is correct
13 Correct 269 ms 38264 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 6 ms 1792 KB Output is correct
17 Correct 116 ms 20088 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 65 ms 12036 KB Output is correct
22 Correct 279 ms 38264 KB Output is correct
23 Correct 287 ms 40672 KB Output is correct
24 Correct 271 ms 38264 KB Output is correct
25 Correct 128 ms 20344 KB Output is correct
26 Correct 107 ms 20856 KB Output is correct
27 Correct 248 ms 40696 KB Output is correct
28 Correct 269 ms 38192 KB Output is correct
29 Correct 106 ms 20344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 64 ms 11856 KB Output is correct
5 Correct 250 ms 38264 KB Output is correct
6 Correct 263 ms 38776 KB Output is correct
7 Correct 267 ms 38188 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 65 ms 12024 KB Output is correct
10 Correct 266 ms 38392 KB Output is correct
11 Correct 316 ms 40696 KB Output is correct
12 Correct 321 ms 38136 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 67 ms 12312 KB Output is correct
17 Correct 273 ms 38264 KB Output is correct
18 Correct 253 ms 39032 KB Output is correct
19 Correct 278 ms 38776 KB Output is correct
20 Correct 253 ms 34416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 12 ms 3200 KB Output is correct
7 Correct 266 ms 38136 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 11 ms 2432 KB Output is correct
13 Correct 251 ms 34040 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 5 ms 1792 KB Output is correct
17 Correct 118 ms 20088 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 66 ms 11896 KB Output is correct
21 Correct 261 ms 38264 KB Output is correct
22 Correct 252 ms 38756 KB Output is correct
23 Correct 267 ms 38136 KB Output is correct
24 Correct 254 ms 34424 KB Output is correct
25 Correct 115 ms 22264 KB Output is correct
26 Correct 104 ms 20476 KB Output is correct
27 Correct 263 ms 38136 KB Output is correct
28 Correct 256 ms 34424 KB Output is correct
29 Correct 0 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 0 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 0 ms 384 KB Output is correct
36 Correct 11 ms 2432 KB Output is correct
37 Correct 251 ms 34168 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 0 ms 384 KB Output is correct
40 Correct 16 ms 3200 KB Output is correct
41 Correct 269 ms 38264 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 6 ms 1792 KB Output is correct
45 Correct 116 ms 20088 KB Output is correct
46 Correct 0 ms 384 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 0 ms 384 KB Output is correct
49 Correct 65 ms 12036 KB Output is correct
50 Correct 279 ms 38264 KB Output is correct
51 Correct 287 ms 40672 KB Output is correct
52 Correct 271 ms 38264 KB Output is correct
53 Correct 128 ms 20344 KB Output is correct
54 Correct 107 ms 20856 KB Output is correct
55 Correct 248 ms 40696 KB Output is correct
56 Correct 269 ms 38192 KB Output is correct
57 Correct 106 ms 20344 KB Output is correct
58 Correct 0 ms 384 KB Output is correct
59 Correct 0 ms 384 KB Output is correct
60 Correct 5 ms 1792 KB Output is correct
61 Correct 114 ms 20088 KB Output is correct
62 Correct 0 ms 384 KB Output is correct
63 Correct 1 ms 384 KB Output is correct
64 Correct 1 ms 384 KB Output is correct
65 Correct 65 ms 12280 KB Output is correct
66 Correct 103 ms 20472 KB Output is correct
67 Correct 117 ms 20704 KB Output is correct
68 Correct 103 ms 22884 KB Output is correct
69 Correct 105 ms 20344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 12 ms 3200 KB Output is correct
7 Correct 266 ms 38136 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 11 ms 2432 KB Output is correct
13 Correct 251 ms 34040 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 5 ms 1792 KB Output is correct
17 Correct 118 ms 20088 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 66 ms 11896 KB Output is correct
21 Correct 261 ms 38264 KB Output is correct
22 Correct 252 ms 38756 KB Output is correct
23 Correct 267 ms 38136 KB Output is correct
24 Correct 254 ms 34424 KB Output is correct
25 Correct 115 ms 22264 KB Output is correct
26 Correct 104 ms 20476 KB Output is correct
27 Correct 263 ms 38136 KB Output is correct
28 Correct 256 ms 34424 KB Output is correct
29 Correct 0 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 0 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 0 ms 384 KB Output is correct
36 Correct 11 ms 2432 KB Output is correct
37 Correct 251 ms 34168 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 0 ms 384 KB Output is correct
40 Correct 16 ms 3200 KB Output is correct
41 Correct 269 ms 38264 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 6 ms 1792 KB Output is correct
45 Correct 116 ms 20088 KB Output is correct
46 Correct 0 ms 384 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 0 ms 384 KB Output is correct
49 Correct 65 ms 12036 KB Output is correct
50 Correct 279 ms 38264 KB Output is correct
51 Correct 287 ms 40672 KB Output is correct
52 Correct 271 ms 38264 KB Output is correct
53 Correct 128 ms 20344 KB Output is correct
54 Correct 107 ms 20856 KB Output is correct
55 Correct 248 ms 40696 KB Output is correct
56 Correct 269 ms 38192 KB Output is correct
57 Correct 106 ms 20344 KB Output is correct
58 Correct 0 ms 384 KB Output is correct
59 Correct 1 ms 384 KB Output is correct
60 Correct 1 ms 384 KB Output is correct
61 Correct 64 ms 11856 KB Output is correct
62 Correct 250 ms 38264 KB Output is correct
63 Correct 263 ms 38776 KB Output is correct
64 Correct 267 ms 38188 KB Output is correct
65 Correct 1 ms 384 KB Output is correct
66 Correct 65 ms 12024 KB Output is correct
67 Correct 266 ms 38392 KB Output is correct
68 Correct 316 ms 40696 KB Output is correct
69 Correct 321 ms 38136 KB Output is correct
70 Correct 1 ms 512 KB Output is correct
71 Correct 1 ms 384 KB Output is correct
72 Correct 0 ms 384 KB Output is correct
73 Correct 67 ms 12312 KB Output is correct
74 Correct 273 ms 38264 KB Output is correct
75 Correct 253 ms 39032 KB Output is correct
76 Correct 278 ms 38776 KB Output is correct
77 Correct 253 ms 34416 KB Output is correct
78 Correct 0 ms 384 KB Output is correct
79 Correct 0 ms 384 KB Output is correct
80 Correct 5 ms 1792 KB Output is correct
81 Correct 114 ms 20088 KB Output is correct
82 Correct 0 ms 384 KB Output is correct
83 Correct 1 ms 384 KB Output is correct
84 Correct 1 ms 384 KB Output is correct
85 Correct 65 ms 12280 KB Output is correct
86 Correct 103 ms 20472 KB Output is correct
87 Correct 117 ms 20704 KB Output is correct
88 Correct 103 ms 22884 KB Output is correct
89 Correct 105 ms 20344 KB Output is correct
90 Correct 0 ms 256 KB Output is correct
91 Correct 1 ms 384 KB Output is correct
92 Correct 5 ms 672 KB Output is correct
93 Correct 102 ms 8184 KB Output is correct
94 Correct 1 ms 384 KB Output is correct
95 Correct 1 ms 384 KB Output is correct
96 Correct 0 ms 384 KB Output is correct
97 Correct 23 ms 2560 KB Output is correct
98 Correct 94 ms 8824 KB Output is correct
99 Correct 95 ms 9976 KB Output is correct
100 Correct 97 ms 9184 KB Output is correct
101 Correct 94 ms 12152 KB Output is correct
102 Correct 102 ms 8184 KB Output is correct
103 Correct 107 ms 8184 KB Output is correct
104 Correct 103 ms 8176 KB Output is correct
105 Correct 101 ms 8184 KB Output is correct