#pragma GCC optimize("Ofast")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include "supertrees.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define e1 first
#define e2 second
#define uint uint_fast64_t
#define ll int_fast64_t
#define ull uint_fast64_t
#define int16 int_fast16_t
#define uint16 uint_fast16_t
#define int32 int_fast32_t
#define uint32 uint_fast32_t
#define int64 int_fast64_t
#define uint64 uint_fast64_t
#define ld long double
#define float long double
#define size(x) (int)x.size()
#define satori int testCases; cin>>testCases; while(testCases--)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define all(r) begin(r),end(r)
#define rall(r) rbegin(r),rend(r)
#define time chrono::high_resolution_clock().now().time_since_epoch().count()
#define elapsed(__begin,__end) (__end-__begin)/CLOCKS_PER_SEC
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
float pi=3.14159265358979323846;
const int MAXN=1e3+10;
bool vis[MAXN],vis2[MAXN];
vector<int> cmp;
int rep[MAXN],sz[MAXN],col[MAXN],cols=0;
void dfs(int u,vector<vector<int>> &g)
{
vis[u]=true;
cmp.eb(u);
for(int v=0;v<size(g);v++)
if(!vis[v]&&g[u][v]==1)
dfs(v,g);
}
int fnd(int u)
{
return (rep[u]==u?u:rep[u]=fnd(rep[u]));
}
void dfs2(int u,vector<vector<int>> &g)
{
vis[u]=true;
col[u]=cols;
if(!vis2[fnd(u)])
vis2[fnd(u)]=true,cmp.eb(fnd(u));
for(int v=0;v<size(g);v++)
if(!vis[v]&&g[u][v])
dfs2(v,g);
}
bool onion(int u,int v)
{
u=fnd(u),v=fnd(v);
if(u==v)
return false;
if(sz[v]>sz[u])
swap(u,v);
sz[u]+=sz[v];
rep[v]=u;
return true;
}
int construct(vector<vector<int>> g)
{
int n=size(g);
vector<vector<int>> res(n,vector<int>(n,0));
for(int i=1;i<=n;i++)
rep[i]=i,sz[i]=1;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
if(g[i][j]==3)
return 0;
for(int i=0;i<n;i++)
if(!vis[i])
{
cmp.clear();
dfs(i,g);
if(size(cmp)==1)
continue;
for(auto u:cmp)
for(auto v:cmp)
if(u!=v&&g[u][v]!=1)
return 0;
for(int i=1;i<size(cmp);i++)
if(onion(cmp[i-1],cmp[i]))
res[cmp[i-1]][cmp[i]]=res[cmp[i]][cmp[i-1]]=1;
}
for(int i=0;i<n;i++)
vis[i]=false;
for(int i=0;i<n;i++)
if(!vis[i])
{
cmp.clear();
cols++;
dfs2(i,g);
if(size(cmp)==1)
continue;
if(size(cmp)==2)
return 0;
for(int i=1;i<size(cmp);i++)
res[cmp[i-1]][cmp[i]]=res[cmp[i]][cmp[i-1]]=1;
res[cmp.back()][cmp[0]]=res[cmp[0]][cmp.back()]=1;
}
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
if(col[i]==col[j])
{
if(fnd(i)==fnd(j))
{
if(g[i][j]!=1)
return 0;
}
else
{
if(g[i][j]!=2)
return 0;
}
}
else
if(g[i][j])
return 0;
build(res);
return 1;
}
Compilation message
supertrees.cpp:2: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
2 | #pragma GCC optimization ("O3")
|
supertrees.cpp:3: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
3 | #pragma GCC optimization ("unroll-loops")
|
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
11 ms |
1280 KB |
Output is correct |
7 |
Correct |
262 ms |
22236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
11 ms |
1280 KB |
Output is correct |
7 |
Correct |
262 ms |
22236 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
512 KB |
Output is correct |
12 |
Correct |
11 ms |
1152 KB |
Output is correct |
13 |
Correct |
263 ms |
22140 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
768 KB |
Output is correct |
17 |
Correct |
115 ms |
12260 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
65 ms |
5856 KB |
Output is correct |
21 |
Correct |
260 ms |
22136 KB |
Output is correct |
22 |
Correct |
259 ms |
22264 KB |
Output is correct |
23 |
Correct |
275 ms |
22136 KB |
Output is correct |
24 |
Correct |
255 ms |
22136 KB |
Output is correct |
25 |
Correct |
111 ms |
12152 KB |
Output is correct |
26 |
Correct |
113 ms |
12152 KB |
Output is correct |
27 |
Correct |
268 ms |
22136 KB |
Output is correct |
28 |
Correct |
252 ms |
22136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
256 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 |
256 KB |
Output is correct |
8 |
Correct |
11 ms |
1184 KB |
Output is correct |
9 |
Correct |
252 ms |
22108 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
11 ms |
1280 KB |
Output is correct |
13 |
Correct |
262 ms |
22136 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
768 KB |
Output is correct |
17 |
Correct |
125 ms |
12280 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
256 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
65 ms |
5756 KB |
Output is correct |
22 |
Correct |
261 ms |
22140 KB |
Output is correct |
23 |
Correct |
261 ms |
22136 KB |
Output is correct |
24 |
Correct |
264 ms |
22136 KB |
Output is correct |
25 |
Correct |
114 ms |
12152 KB |
Output is correct |
26 |
Correct |
114 ms |
12152 KB |
Output is correct |
27 |
Correct |
275 ms |
22168 KB |
Output is correct |
28 |
Correct |
267 ms |
22136 KB |
Output is correct |
29 |
Correct |
113 ms |
12280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
67 ms |
5880 KB |
Output is correct |
5 |
Correct |
261 ms |
22136 KB |
Output is correct |
6 |
Correct |
257 ms |
22224 KB |
Output is correct |
7 |
Correct |
265 ms |
22136 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
65 ms |
5880 KB |
Output is correct |
10 |
Correct |
255 ms |
22136 KB |
Output is correct |
11 |
Correct |
256 ms |
22264 KB |
Output is correct |
12 |
Correct |
261 ms |
22136 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
64 ms |
5752 KB |
Output is correct |
17 |
Correct |
259 ms |
22136 KB |
Output is correct |
18 |
Correct |
261 ms |
22136 KB |
Output is correct |
19 |
Correct |
258 ms |
22136 KB |
Output is correct |
20 |
Correct |
254 ms |
22136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
11 ms |
1280 KB |
Output is correct |
7 |
Correct |
262 ms |
22236 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
512 KB |
Output is correct |
12 |
Correct |
11 ms |
1152 KB |
Output is correct |
13 |
Correct |
263 ms |
22140 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
768 KB |
Output is correct |
17 |
Correct |
115 ms |
12260 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
65 ms |
5856 KB |
Output is correct |
21 |
Correct |
260 ms |
22136 KB |
Output is correct |
22 |
Correct |
259 ms |
22264 KB |
Output is correct |
23 |
Correct |
275 ms |
22136 KB |
Output is correct |
24 |
Correct |
255 ms |
22136 KB |
Output is correct |
25 |
Correct |
111 ms |
12152 KB |
Output is correct |
26 |
Correct |
113 ms |
12152 KB |
Output is correct |
27 |
Correct |
268 ms |
22136 KB |
Output is correct |
28 |
Correct |
252 ms |
22136 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
1 ms |
384 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
256 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 |
256 KB |
Output is correct |
36 |
Correct |
11 ms |
1184 KB |
Output is correct |
37 |
Correct |
252 ms |
22108 KB |
Output is correct |
38 |
Correct |
1 ms |
256 KB |
Output is correct |
39 |
Correct |
1 ms |
384 KB |
Output is correct |
40 |
Correct |
11 ms |
1280 KB |
Output is correct |
41 |
Correct |
262 ms |
22136 KB |
Output is correct |
42 |
Correct |
1 ms |
256 KB |
Output is correct |
43 |
Correct |
1 ms |
384 KB |
Output is correct |
44 |
Correct |
5 ms |
768 KB |
Output is correct |
45 |
Correct |
125 ms |
12280 KB |
Output is correct |
46 |
Correct |
1 ms |
384 KB |
Output is correct |
47 |
Correct |
1 ms |
256 KB |
Output is correct |
48 |
Correct |
1 ms |
384 KB |
Output is correct |
49 |
Correct |
65 ms |
5756 KB |
Output is correct |
50 |
Correct |
261 ms |
22140 KB |
Output is correct |
51 |
Correct |
261 ms |
22136 KB |
Output is correct |
52 |
Correct |
264 ms |
22136 KB |
Output is correct |
53 |
Correct |
114 ms |
12152 KB |
Output is correct |
54 |
Correct |
114 ms |
12152 KB |
Output is correct |
55 |
Correct |
275 ms |
22168 KB |
Output is correct |
56 |
Correct |
267 ms |
22136 KB |
Output is correct |
57 |
Correct |
113 ms |
12280 KB |
Output is correct |
58 |
Correct |
1 ms |
256 KB |
Output is correct |
59 |
Correct |
1 ms |
384 KB |
Output is correct |
60 |
Correct |
5 ms |
768 KB |
Output is correct |
61 |
Correct |
116 ms |
12280 KB |
Output is correct |
62 |
Correct |
1 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 |
64 ms |
5752 KB |
Output is correct |
66 |
Correct |
113 ms |
12152 KB |
Output is correct |
67 |
Correct |
109 ms |
12152 KB |
Output is correct |
68 |
Correct |
118 ms |
12152 KB |
Output is correct |
69 |
Correct |
110 ms |
12280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
11 ms |
1280 KB |
Output is correct |
7 |
Correct |
262 ms |
22236 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
512 KB |
Output is correct |
12 |
Correct |
11 ms |
1152 KB |
Output is correct |
13 |
Correct |
263 ms |
22140 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
768 KB |
Output is correct |
17 |
Correct |
115 ms |
12260 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
65 ms |
5856 KB |
Output is correct |
21 |
Correct |
260 ms |
22136 KB |
Output is correct |
22 |
Correct |
259 ms |
22264 KB |
Output is correct |
23 |
Correct |
275 ms |
22136 KB |
Output is correct |
24 |
Correct |
255 ms |
22136 KB |
Output is correct |
25 |
Correct |
111 ms |
12152 KB |
Output is correct |
26 |
Correct |
113 ms |
12152 KB |
Output is correct |
27 |
Correct |
268 ms |
22136 KB |
Output is correct |
28 |
Correct |
252 ms |
22136 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
1 ms |
384 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
256 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 |
256 KB |
Output is correct |
36 |
Correct |
11 ms |
1184 KB |
Output is correct |
37 |
Correct |
252 ms |
22108 KB |
Output is correct |
38 |
Correct |
1 ms |
256 KB |
Output is correct |
39 |
Correct |
1 ms |
384 KB |
Output is correct |
40 |
Correct |
11 ms |
1280 KB |
Output is correct |
41 |
Correct |
262 ms |
22136 KB |
Output is correct |
42 |
Correct |
1 ms |
256 KB |
Output is correct |
43 |
Correct |
1 ms |
384 KB |
Output is correct |
44 |
Correct |
5 ms |
768 KB |
Output is correct |
45 |
Correct |
125 ms |
12280 KB |
Output is correct |
46 |
Correct |
1 ms |
384 KB |
Output is correct |
47 |
Correct |
1 ms |
256 KB |
Output is correct |
48 |
Correct |
1 ms |
384 KB |
Output is correct |
49 |
Correct |
65 ms |
5756 KB |
Output is correct |
50 |
Correct |
261 ms |
22140 KB |
Output is correct |
51 |
Correct |
261 ms |
22136 KB |
Output is correct |
52 |
Correct |
264 ms |
22136 KB |
Output is correct |
53 |
Correct |
114 ms |
12152 KB |
Output is correct |
54 |
Correct |
114 ms |
12152 KB |
Output is correct |
55 |
Correct |
275 ms |
22168 KB |
Output is correct |
56 |
Correct |
267 ms |
22136 KB |
Output is correct |
57 |
Correct |
113 ms |
12280 KB |
Output is correct |
58 |
Correct |
1 ms |
384 KB |
Output is correct |
59 |
Correct |
1 ms |
256 KB |
Output is correct |
60 |
Correct |
1 ms |
384 KB |
Output is correct |
61 |
Correct |
67 ms |
5880 KB |
Output is correct |
62 |
Correct |
261 ms |
22136 KB |
Output is correct |
63 |
Correct |
257 ms |
22224 KB |
Output is correct |
64 |
Correct |
265 ms |
22136 KB |
Output is correct |
65 |
Correct |
1 ms |
256 KB |
Output is correct |
66 |
Correct |
65 ms |
5880 KB |
Output is correct |
67 |
Correct |
255 ms |
22136 KB |
Output is correct |
68 |
Correct |
256 ms |
22264 KB |
Output is correct |
69 |
Correct |
261 ms |
22136 KB |
Output is correct |
70 |
Correct |
1 ms |
384 KB |
Output is correct |
71 |
Correct |
1 ms |
384 KB |
Output is correct |
72 |
Correct |
1 ms |
384 KB |
Output is correct |
73 |
Correct |
64 ms |
5752 KB |
Output is correct |
74 |
Correct |
259 ms |
22136 KB |
Output is correct |
75 |
Correct |
261 ms |
22136 KB |
Output is correct |
76 |
Correct |
258 ms |
22136 KB |
Output is correct |
77 |
Correct |
254 ms |
22136 KB |
Output is correct |
78 |
Correct |
1 ms |
256 KB |
Output is correct |
79 |
Correct |
1 ms |
384 KB |
Output is correct |
80 |
Correct |
5 ms |
768 KB |
Output is correct |
81 |
Correct |
116 ms |
12280 KB |
Output is correct |
82 |
Correct |
1 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 |
64 ms |
5752 KB |
Output is correct |
86 |
Correct |
113 ms |
12152 KB |
Output is correct |
87 |
Correct |
109 ms |
12152 KB |
Output is correct |
88 |
Correct |
118 ms |
12152 KB |
Output is correct |
89 |
Correct |
110 ms |
12280 KB |
Output is correct |
90 |
Correct |
1 ms |
256 KB |
Output is correct |
91 |
Correct |
1 ms |
384 KB |
Output is correct |
92 |
Correct |
5 ms |
896 KB |
Output is correct |
93 |
Correct |
113 ms |
12152 KB |
Output is correct |
94 |
Correct |
1 ms |
256 KB |
Output is correct |
95 |
Correct |
1 ms |
256 KB |
Output is correct |
96 |
Correct |
1 ms |
384 KB |
Output is correct |
97 |
Correct |
28 ms |
3320 KB |
Output is correct |
98 |
Correct |
114 ms |
12152 KB |
Output is correct |
99 |
Correct |
107 ms |
12152 KB |
Output is correct |
100 |
Correct |
110 ms |
12152 KB |
Output is correct |
101 |
Correct |
108 ms |
12280 KB |
Output is correct |
102 |
Correct |
113 ms |
12152 KB |
Output is correct |
103 |
Correct |
109 ms |
12152 KB |
Output is correct |
104 |
Correct |
113 ms |
12152 KB |
Output is correct |
105 |
Correct |
113 ms |
12152 KB |
Output is correct |