#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];
}
}
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:64: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]
64 | for(ll j=1;j<v.size();j++)
| ~^~~~~~~~~
supertrees.cpp:98: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]
98 | for(ll j=0;j<x.size();j++)
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 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 |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
13 ms |
3200 KB |
Output is correct |
7 |
Correct |
267 ms |
38112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 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 |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
13 ms |
3200 KB |
Output is correct |
7 |
Correct |
267 ms |
38112 KB |
Output is correct |
8 |
Correct |
0 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 |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
11 ms |
2432 KB |
Output is correct |
13 |
Correct |
253 ms |
34040 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 |
119 ms |
20088 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
65 ms |
11896 KB |
Output is correct |
21 |
Correct |
259 ms |
38392 KB |
Output is correct |
22 |
Correct |
260 ms |
38776 KB |
Output is correct |
23 |
Correct |
270 ms |
38264 KB |
Output is correct |
24 |
Correct |
256 ms |
34296 KB |
Output is correct |
25 |
Correct |
114 ms |
22264 KB |
Output is correct |
26 |
Correct |
108 ms |
20472 KB |
Output is correct |
27 |
Correct |
270 ms |
38108 KB |
Output is correct |
28 |
Correct |
249 ms |
34296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
12 ms |
2432 KB |
Output is correct |
9 |
Correct |
254 ms |
34144 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
12 ms |
3200 KB |
Output is correct |
13 |
Correct |
268 ms |
38136 KB |
Output is correct |
14 |
Correct |
0 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 |
133 ms |
20216 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
67 ms |
12024 KB |
Output is correct |
22 |
Correct |
255 ms |
38392 KB |
Output is correct |
23 |
Correct |
257 ms |
40672 KB |
Output is correct |
24 |
Correct |
272 ms |
38392 KB |
Output is correct |
25 |
Correct |
115 ms |
20344 KB |
Output is correct |
26 |
Correct |
115 ms |
20856 KB |
Output is correct |
27 |
Correct |
268 ms |
40800 KB |
Output is correct |
28 |
Correct |
271 ms |
38136 KB |
Output is correct |
29 |
Correct |
116 ms |
20344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
68 ms |
11896 KB |
Output is correct |
5 |
Correct |
255 ms |
38264 KB |
Output is correct |
6 |
Correct |
268 ms |
38752 KB |
Output is correct |
7 |
Correct |
284 ms |
38136 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
65 ms |
12032 KB |
Output is correct |
10 |
Correct |
265 ms |
38264 KB |
Output is correct |
11 |
Correct |
262 ms |
40696 KB |
Output is correct |
12 |
Correct |
279 ms |
38136 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
66 ms |
12408 KB |
Output is correct |
17 |
Correct |
260 ms |
38392 KB |
Output is correct |
18 |
Correct |
275 ms |
39032 KB |
Output is correct |
19 |
Correct |
261 ms |
38776 KB |
Output is correct |
20 |
Correct |
255 ms |
34296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 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 |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
13 ms |
3200 KB |
Output is correct |
7 |
Correct |
267 ms |
38112 KB |
Output is correct |
8 |
Correct |
0 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 |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
11 ms |
2432 KB |
Output is correct |
13 |
Correct |
253 ms |
34040 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 |
119 ms |
20088 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
65 ms |
11896 KB |
Output is correct |
21 |
Correct |
259 ms |
38392 KB |
Output is correct |
22 |
Correct |
260 ms |
38776 KB |
Output is correct |
23 |
Correct |
270 ms |
38264 KB |
Output is correct |
24 |
Correct |
256 ms |
34296 KB |
Output is correct |
25 |
Correct |
114 ms |
22264 KB |
Output is correct |
26 |
Correct |
108 ms |
20472 KB |
Output is correct |
27 |
Correct |
270 ms |
38108 KB |
Output is correct |
28 |
Correct |
249 ms |
34296 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
0 ms |
384 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
0 ms |
384 KB |
Output is correct |
33 |
Correct |
1 ms |
384 KB |
Output is correct |
34 |
Correct |
1 ms |
384 KB |
Output is correct |
35 |
Correct |
1 ms |
384 KB |
Output is correct |
36 |
Correct |
12 ms |
2432 KB |
Output is correct |
37 |
Correct |
254 ms |
34144 KB |
Output is correct |
38 |
Correct |
1 ms |
384 KB |
Output is correct |
39 |
Correct |
1 ms |
384 KB |
Output is correct |
40 |
Correct |
12 ms |
3200 KB |
Output is correct |
41 |
Correct |
268 ms |
38136 KB |
Output is correct |
42 |
Correct |
0 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 |
133 ms |
20216 KB |
Output is correct |
46 |
Correct |
0 ms |
384 KB |
Output is correct |
47 |
Correct |
1 ms |
384 KB |
Output is correct |
48 |
Correct |
1 ms |
384 KB |
Output is correct |
49 |
Correct |
67 ms |
12024 KB |
Output is correct |
50 |
Correct |
255 ms |
38392 KB |
Output is correct |
51 |
Correct |
257 ms |
40672 KB |
Output is correct |
52 |
Correct |
272 ms |
38392 KB |
Output is correct |
53 |
Correct |
115 ms |
20344 KB |
Output is correct |
54 |
Correct |
115 ms |
20856 KB |
Output is correct |
55 |
Correct |
268 ms |
40800 KB |
Output is correct |
56 |
Correct |
271 ms |
38136 KB |
Output is correct |
57 |
Correct |
116 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 |
6 ms |
1792 KB |
Output is correct |
61 |
Correct |
124 ms |
20088 KB |
Output is correct |
62 |
Correct |
0 ms |
384 KB |
Output is correct |
63 |
Correct |
0 ms |
384 KB |
Output is correct |
64 |
Correct |
1 ms |
384 KB |
Output is correct |
65 |
Correct |
66 ms |
12280 KB |
Output is correct |
66 |
Correct |
112 ms |
20472 KB |
Output is correct |
67 |
Correct |
113 ms |
20728 KB |
Output is correct |
68 |
Correct |
114 ms |
22904 KB |
Output is correct |
69 |
Correct |
111 ms |
20344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 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 |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
13 ms |
3200 KB |
Output is correct |
7 |
Correct |
267 ms |
38112 KB |
Output is correct |
8 |
Correct |
0 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 |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
11 ms |
2432 KB |
Output is correct |
13 |
Correct |
253 ms |
34040 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 |
119 ms |
20088 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
65 ms |
11896 KB |
Output is correct |
21 |
Correct |
259 ms |
38392 KB |
Output is correct |
22 |
Correct |
260 ms |
38776 KB |
Output is correct |
23 |
Correct |
270 ms |
38264 KB |
Output is correct |
24 |
Correct |
256 ms |
34296 KB |
Output is correct |
25 |
Correct |
114 ms |
22264 KB |
Output is correct |
26 |
Correct |
108 ms |
20472 KB |
Output is correct |
27 |
Correct |
270 ms |
38108 KB |
Output is correct |
28 |
Correct |
249 ms |
34296 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
0 ms |
384 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
0 ms |
384 KB |
Output is correct |
33 |
Correct |
1 ms |
384 KB |
Output is correct |
34 |
Correct |
1 ms |
384 KB |
Output is correct |
35 |
Correct |
1 ms |
384 KB |
Output is correct |
36 |
Correct |
12 ms |
2432 KB |
Output is correct |
37 |
Correct |
254 ms |
34144 KB |
Output is correct |
38 |
Correct |
1 ms |
384 KB |
Output is correct |
39 |
Correct |
1 ms |
384 KB |
Output is correct |
40 |
Correct |
12 ms |
3200 KB |
Output is correct |
41 |
Correct |
268 ms |
38136 KB |
Output is correct |
42 |
Correct |
0 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 |
133 ms |
20216 KB |
Output is correct |
46 |
Correct |
0 ms |
384 KB |
Output is correct |
47 |
Correct |
1 ms |
384 KB |
Output is correct |
48 |
Correct |
1 ms |
384 KB |
Output is correct |
49 |
Correct |
67 ms |
12024 KB |
Output is correct |
50 |
Correct |
255 ms |
38392 KB |
Output is correct |
51 |
Correct |
257 ms |
40672 KB |
Output is correct |
52 |
Correct |
272 ms |
38392 KB |
Output is correct |
53 |
Correct |
115 ms |
20344 KB |
Output is correct |
54 |
Correct |
115 ms |
20856 KB |
Output is correct |
55 |
Correct |
268 ms |
40800 KB |
Output is correct |
56 |
Correct |
271 ms |
38136 KB |
Output is correct |
57 |
Correct |
116 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 |
0 ms |
384 KB |
Output is correct |
61 |
Correct |
68 ms |
11896 KB |
Output is correct |
62 |
Correct |
255 ms |
38264 KB |
Output is correct |
63 |
Correct |
268 ms |
38752 KB |
Output is correct |
64 |
Correct |
284 ms |
38136 KB |
Output is correct |
65 |
Correct |
1 ms |
384 KB |
Output is correct |
66 |
Correct |
65 ms |
12032 KB |
Output is correct |
67 |
Correct |
265 ms |
38264 KB |
Output is correct |
68 |
Correct |
262 ms |
40696 KB |
Output is correct |
69 |
Correct |
279 ms |
38136 KB |
Output is correct |
70 |
Correct |
0 ms |
384 KB |
Output is correct |
71 |
Correct |
1 ms |
384 KB |
Output is correct |
72 |
Correct |
0 ms |
384 KB |
Output is correct |
73 |
Correct |
66 ms |
12408 KB |
Output is correct |
74 |
Correct |
260 ms |
38392 KB |
Output is correct |
75 |
Correct |
275 ms |
39032 KB |
Output is correct |
76 |
Correct |
261 ms |
38776 KB |
Output is correct |
77 |
Correct |
255 ms |
34296 KB |
Output is correct |
78 |
Correct |
0 ms |
384 KB |
Output is correct |
79 |
Correct |
1 ms |
384 KB |
Output is correct |
80 |
Correct |
6 ms |
1792 KB |
Output is correct |
81 |
Correct |
124 ms |
20088 KB |
Output is correct |
82 |
Correct |
0 ms |
384 KB |
Output is correct |
83 |
Correct |
0 ms |
384 KB |
Output is correct |
84 |
Correct |
1 ms |
384 KB |
Output is correct |
85 |
Correct |
66 ms |
12280 KB |
Output is correct |
86 |
Correct |
112 ms |
20472 KB |
Output is correct |
87 |
Correct |
113 ms |
20728 KB |
Output is correct |
88 |
Correct |
114 ms |
22904 KB |
Output is correct |
89 |
Correct |
111 ms |
20344 KB |
Output is correct |
90 |
Correct |
0 ms |
384 KB |
Output is correct |
91 |
Correct |
0 ms |
384 KB |
Output is correct |
92 |
Correct |
6 ms |
1792 KB |
Output is correct |
93 |
Correct |
121 ms |
20060 KB |
Output is correct |
94 |
Incorrect |
1 ms |
384 KB |
Answer gives possible 1 while actual possible 0 |
95 |
Halted |
0 ms |
0 KB |
- |