/*input
*/
/**
Author: Kristopher Paul
Date Created: 30-09-2020
**/
#include<bits/stdc++.h>
#include<stdio.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
//#define int ll
#define pb push_back
#define INF 1e18
//#define MOD 1000000007
#define MOD 998244353
#define mp make_pair
const double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define umap map
#define pii pair<int,int>
#define F first
#define S second
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define itr :: iterator it
#define all(v) v.begin(),v.end()
#define WL(t) while(t--)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define out(x) cout << #x << " is " << x << endl
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
//Uncomment for File I/O
//ifstream fin("input.in")
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds; // set
//typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> pbds; // multiset
int ModExp(int x,int y,int m){
int res = 1;
x = x % m;
while (y > 0)
{
if (y & 1)
res = (res*x) % m;
y = y>>1;
x = (x*x) % m;
}
return res;
}
void build(vector<vi> b);
int par[1005];
int ran[1005];
int type[1005];
int fpar(int x){
if(x == par[x]){
return x;
}
return par[x] = fpar(par[x]);
}
void uni(int u,int v){
int a = fpar(u);
int b = fpar(v);
if(a == b){
return;
}
if(ran[a] < ran[b]){
par[a] = b;
}else if(ran[b] < ran[a]){
par[b] = a;
}else{
par[a] = b;
ran[b]++;
}
}
void rec(){
rec();
}
int construct(vector<vi> p){
int n = p.size();
FOR(i,0,n){
par[i] = i;
ran[i] = 1;
type[i] = 0;
}
vector<vi> ans(n,vi(n,0));
FOR(i,0,n){
FOR(j,0,n){
if(p[i][j] == 2){
uni(i,j);
if(type[i] == 1 || type[j] == 1){
rec();
return 0;
}
type[i] = type[j] = 2;
}
if(p[i][j] == 1 && i != j){
uni(i,j);
if(type[i] == 2 || type[j] == 2){
rec();
return 0;
}
type[i] = type[j] = 1;
}
}
}
bool vis[n] = {};
vector<vi> conp(n,vi(n,0));
FOR(i,0,n){
if(!vis[par[i]]){
vis[par[i]] = true;
vi nodes;
set<int> tmp;
FOR(j,0,n){
if(par[j] == par[i]){
nodes.pb(j);
tmp.insert(type[j]);
}
}
if(tmp.size() != 1){
return 0;
}
int tt = *tmp.begin();
int sz = nodes.size();
if(sz == 1){
conp[nodes[0]][nodes[0]] = 1;
continue;
}
if(sz == 2 && tt == 2){
return 0;
}
FOR(ind,0,nodes.size()){
if(ind != 0){
ans[nodes[ind]][nodes[ind-1]] = 1;
}else if(tt == 2){
ans[nodes[ind]][nodes[sz-1]] = 1;
}
if(ind != (sz-1)){
ans[nodes[ind]][nodes[ind+1]] = 1;
}else if(tt == 2){
ans[nodes[ind]][nodes[0]] = 1;
}
FOR(iind,0,sz){
if(ind == iind){
conp[nodes[ind]][nodes[iind]] = 1;
continue;
}
if(tt == 2){
conp[nodes[ind]][nodes[iind]] = 2;
}else{
conp[nodes[ind]][nodes[iind]] = 1;
}
}
}
}
}
if(p != conp){
//rec();
return 0;
}
build(ans);
return 1;
}
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:21:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | #define FOR(i,a,b) for (int i = a; i < b; i++)
......
150 | FOR(ind,0,nodes.size()){
| ~~~~~~~~~~~~~~~~~~
supertrees.cpp:150:13: note: in expansion of macro 'FOR'
150 | FOR(ind,0,nodes.size()){
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
11 ms |
1408 KB |
Output is correct |
7 |
Correct |
255 ms |
26216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
11 ms |
1408 KB |
Output is correct |
7 |
Correct |
255 ms |
26216 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
10 ms |
1408 KB |
Output is correct |
13 |
Correct |
240 ms |
26104 KB |
Output is correct |
14 |
Correct |
0 ms |
256 KB |
Output is correct |
15 |
Correct |
0 ms |
256 KB |
Output is correct |
16 |
Correct |
5 ms |
1024 KB |
Output is correct |
17 |
Correct |
123 ms |
16120 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
0 ms |
256 KB |
Output is correct |
20 |
Correct |
62 ms |
6776 KB |
Output is correct |
21 |
Correct |
244 ms |
26104 KB |
Output is correct |
22 |
Correct |
243 ms |
26056 KB |
Output is correct |
23 |
Correct |
257 ms |
26104 KB |
Output is correct |
24 |
Correct |
247 ms |
26104 KB |
Output is correct |
25 |
Correct |
104 ms |
16120 KB |
Output is correct |
26 |
Correct |
101 ms |
16096 KB |
Output is correct |
27 |
Correct |
268 ms |
26104 KB |
Output is correct |
28 |
Correct |
247 ms |
26104 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 |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
10 ms |
1408 KB |
Output is correct |
9 |
Correct |
256 ms |
26104 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
256 KB |
Output is correct |
12 |
Correct |
11 ms |
1408 KB |
Output is correct |
13 |
Correct |
255 ms |
26080 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
256 KB |
Output is correct |
16 |
Correct |
6 ms |
1024 KB |
Output is correct |
17 |
Correct |
122 ms |
16096 KB |
Output is correct |
18 |
Correct |
0 ms |
256 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
0 ms |
256 KB |
Output is correct |
21 |
Correct |
61 ms |
6776 KB |
Output is correct |
22 |
Correct |
244 ms |
26108 KB |
Output is correct |
23 |
Correct |
239 ms |
26104 KB |
Output is correct |
24 |
Correct |
263 ms |
26120 KB |
Output is correct |
25 |
Correct |
103 ms |
16120 KB |
Output is correct |
26 |
Correct |
102 ms |
16120 KB |
Output is correct |
27 |
Correct |
249 ms |
26136 KB |
Output is correct |
28 |
Correct |
261 ms |
26232 KB |
Output is correct |
29 |
Correct |
101 ms |
16120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
64 ms |
6860 KB |
Output is correct |
5 |
Correct |
250 ms |
26232 KB |
Output is correct |
6 |
Correct |
244 ms |
26104 KB |
Output is correct |
7 |
Correct |
261 ms |
26104 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
64 ms |
6868 KB |
Output is correct |
10 |
Correct |
244 ms |
26108 KB |
Output is correct |
11 |
Correct |
241 ms |
26104 KB |
Output is correct |
12 |
Correct |
263 ms |
26104 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
256 KB |
Output is correct |
15 |
Execution timed out |
1089 ms |
256 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
11 ms |
1408 KB |
Output is correct |
7 |
Correct |
255 ms |
26216 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
10 ms |
1408 KB |
Output is correct |
13 |
Correct |
240 ms |
26104 KB |
Output is correct |
14 |
Correct |
0 ms |
256 KB |
Output is correct |
15 |
Correct |
0 ms |
256 KB |
Output is correct |
16 |
Correct |
5 ms |
1024 KB |
Output is correct |
17 |
Correct |
123 ms |
16120 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
0 ms |
256 KB |
Output is correct |
20 |
Correct |
62 ms |
6776 KB |
Output is correct |
21 |
Correct |
244 ms |
26104 KB |
Output is correct |
22 |
Correct |
243 ms |
26056 KB |
Output is correct |
23 |
Correct |
257 ms |
26104 KB |
Output is correct |
24 |
Correct |
247 ms |
26104 KB |
Output is correct |
25 |
Correct |
104 ms |
16120 KB |
Output is correct |
26 |
Correct |
101 ms |
16096 KB |
Output is correct |
27 |
Correct |
268 ms |
26104 KB |
Output is correct |
28 |
Correct |
247 ms |
26104 KB |
Output is correct |
29 |
Correct |
0 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 |
256 KB |
Output is correct |
33 |
Correct |
0 ms |
384 KB |
Output is correct |
34 |
Correct |
1 ms |
256 KB |
Output is correct |
35 |
Correct |
1 ms |
384 KB |
Output is correct |
36 |
Correct |
10 ms |
1408 KB |
Output is correct |
37 |
Correct |
256 ms |
26104 KB |
Output is correct |
38 |
Correct |
0 ms |
384 KB |
Output is correct |
39 |
Correct |
0 ms |
256 KB |
Output is correct |
40 |
Correct |
11 ms |
1408 KB |
Output is correct |
41 |
Correct |
255 ms |
26080 KB |
Output is correct |
42 |
Correct |
1 ms |
256 KB |
Output is correct |
43 |
Correct |
1 ms |
256 KB |
Output is correct |
44 |
Correct |
6 ms |
1024 KB |
Output is correct |
45 |
Correct |
122 ms |
16096 KB |
Output is correct |
46 |
Correct |
0 ms |
256 KB |
Output is correct |
47 |
Correct |
0 ms |
384 KB |
Output is correct |
48 |
Correct |
0 ms |
256 KB |
Output is correct |
49 |
Correct |
61 ms |
6776 KB |
Output is correct |
50 |
Correct |
244 ms |
26108 KB |
Output is correct |
51 |
Correct |
239 ms |
26104 KB |
Output is correct |
52 |
Correct |
263 ms |
26120 KB |
Output is correct |
53 |
Correct |
103 ms |
16120 KB |
Output is correct |
54 |
Correct |
102 ms |
16120 KB |
Output is correct |
55 |
Correct |
249 ms |
26136 KB |
Output is correct |
56 |
Correct |
261 ms |
26232 KB |
Output is correct |
57 |
Correct |
101 ms |
16120 KB |
Output is correct |
58 |
Execution timed out |
1091 ms |
256 KB |
Time limit exceeded |
59 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
11 ms |
1408 KB |
Output is correct |
7 |
Correct |
255 ms |
26216 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
10 ms |
1408 KB |
Output is correct |
13 |
Correct |
240 ms |
26104 KB |
Output is correct |
14 |
Correct |
0 ms |
256 KB |
Output is correct |
15 |
Correct |
0 ms |
256 KB |
Output is correct |
16 |
Correct |
5 ms |
1024 KB |
Output is correct |
17 |
Correct |
123 ms |
16120 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
0 ms |
256 KB |
Output is correct |
20 |
Correct |
62 ms |
6776 KB |
Output is correct |
21 |
Correct |
244 ms |
26104 KB |
Output is correct |
22 |
Correct |
243 ms |
26056 KB |
Output is correct |
23 |
Correct |
257 ms |
26104 KB |
Output is correct |
24 |
Correct |
247 ms |
26104 KB |
Output is correct |
25 |
Correct |
104 ms |
16120 KB |
Output is correct |
26 |
Correct |
101 ms |
16096 KB |
Output is correct |
27 |
Correct |
268 ms |
26104 KB |
Output is correct |
28 |
Correct |
247 ms |
26104 KB |
Output is correct |
29 |
Correct |
0 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 |
256 KB |
Output is correct |
33 |
Correct |
0 ms |
384 KB |
Output is correct |
34 |
Correct |
1 ms |
256 KB |
Output is correct |
35 |
Correct |
1 ms |
384 KB |
Output is correct |
36 |
Correct |
10 ms |
1408 KB |
Output is correct |
37 |
Correct |
256 ms |
26104 KB |
Output is correct |
38 |
Correct |
0 ms |
384 KB |
Output is correct |
39 |
Correct |
0 ms |
256 KB |
Output is correct |
40 |
Correct |
11 ms |
1408 KB |
Output is correct |
41 |
Correct |
255 ms |
26080 KB |
Output is correct |
42 |
Correct |
1 ms |
256 KB |
Output is correct |
43 |
Correct |
1 ms |
256 KB |
Output is correct |
44 |
Correct |
6 ms |
1024 KB |
Output is correct |
45 |
Correct |
122 ms |
16096 KB |
Output is correct |
46 |
Correct |
0 ms |
256 KB |
Output is correct |
47 |
Correct |
0 ms |
384 KB |
Output is correct |
48 |
Correct |
0 ms |
256 KB |
Output is correct |
49 |
Correct |
61 ms |
6776 KB |
Output is correct |
50 |
Correct |
244 ms |
26108 KB |
Output is correct |
51 |
Correct |
239 ms |
26104 KB |
Output is correct |
52 |
Correct |
263 ms |
26120 KB |
Output is correct |
53 |
Correct |
103 ms |
16120 KB |
Output is correct |
54 |
Correct |
102 ms |
16120 KB |
Output is correct |
55 |
Correct |
249 ms |
26136 KB |
Output is correct |
56 |
Correct |
261 ms |
26232 KB |
Output is correct |
57 |
Correct |
101 ms |
16120 KB |
Output is correct |
58 |
Correct |
0 ms |
384 KB |
Output is correct |
59 |
Correct |
0 ms |
256 KB |
Output is correct |
60 |
Correct |
0 ms |
256 KB |
Output is correct |
61 |
Correct |
64 ms |
6860 KB |
Output is correct |
62 |
Correct |
250 ms |
26232 KB |
Output is correct |
63 |
Correct |
244 ms |
26104 KB |
Output is correct |
64 |
Correct |
261 ms |
26104 KB |
Output is correct |
65 |
Correct |
0 ms |
384 KB |
Output is correct |
66 |
Correct |
64 ms |
6868 KB |
Output is correct |
67 |
Correct |
244 ms |
26108 KB |
Output is correct |
68 |
Correct |
241 ms |
26104 KB |
Output is correct |
69 |
Correct |
263 ms |
26104 KB |
Output is correct |
70 |
Correct |
1 ms |
384 KB |
Output is correct |
71 |
Correct |
0 ms |
256 KB |
Output is correct |
72 |
Execution timed out |
1089 ms |
256 KB |
Time limit exceeded |
73 |
Halted |
0 ms |
0 KB |
- |