/*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){
return 0;
}
type[i] = type[j] = 2;
}
if(p[i][j] == 1 && i != j){
uni(i,j);
if(type[i] == 2 || type[j] == 2){
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){
rec();
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;
}
}
}
}
}
/*FOR(i,0,n){
FOR(j,0,n){
cout << ans[i][j] << " ";
}
cout << endl;
}*/
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++)
......
149 | FOR(ind,0,nodes.size()){
| ~~~~~~~~~~~~~~~~~~
supertrees.cpp:149:13: note: in expansion of macro 'FOR'
149 | FOR(ind,0,nodes.size()){
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
11 ms |
1408 KB |
Output is correct |
7 |
Correct |
256 ms |
26104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
11 ms |
1408 KB |
Output is correct |
7 |
Correct |
256 ms |
26104 KB |
Output is correct |
8 |
Correct |
0 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
256 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 |
1436 KB |
Output is correct |
13 |
Correct |
245 ms |
26104 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
1024 KB |
Output is correct |
17 |
Correct |
123 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 |
62 ms |
6776 KB |
Output is correct |
21 |
Correct |
248 ms |
26104 KB |
Output is correct |
22 |
Correct |
245 ms |
26104 KB |
Output is correct |
23 |
Correct |
260 ms |
26104 KB |
Output is correct |
24 |
Correct |
243 ms |
26104 KB |
Output is correct |
25 |
Correct |
102 ms |
16120 KB |
Output is correct |
26 |
Correct |
100 ms |
16120 KB |
Output is correct |
27 |
Correct |
262 ms |
26104 KB |
Output is correct |
28 |
Correct |
241 ms |
26104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
11 ms |
1408 KB |
Output is correct |
9 |
Correct |
251 ms |
26104 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
256 KB |
Output is correct |
12 |
Correct |
11 ms |
1408 KB |
Output is correct |
13 |
Correct |
260 ms |
26200 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 |
126 ms |
16120 KB |
Output is correct |
18 |
Correct |
0 ms |
256 KB |
Output is correct |
19 |
Correct |
1 ms |
256 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
61 ms |
6776 KB |
Output is correct |
22 |
Correct |
246 ms |
26104 KB |
Output is correct |
23 |
Correct |
247 ms |
26104 KB |
Output is correct |
24 |
Correct |
264 ms |
26232 KB |
Output is correct |
25 |
Correct |
106 ms |
16124 KB |
Output is correct |
26 |
Correct |
106 ms |
16120 KB |
Output is correct |
27 |
Correct |
244 ms |
26104 KB |
Output is correct |
28 |
Correct |
260 ms |
26236 KB |
Output is correct |
29 |
Correct |
102 ms |
16092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
61 ms |
6776 KB |
Output is correct |
5 |
Correct |
249 ms |
26104 KB |
Output is correct |
6 |
Correct |
242 ms |
26104 KB |
Output is correct |
7 |
Correct |
274 ms |
26232 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
61 ms |
6776 KB |
Output is correct |
10 |
Correct |
246 ms |
25976 KB |
Output is correct |
11 |
Correct |
243 ms |
25976 KB |
Output is correct |
12 |
Correct |
261 ms |
26104 KB |
Output is correct |
13 |
Correct |
1 ms |
256 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Incorrect |
1 ms |
256 KB |
Answer gives possible 0 while actual possible 1 |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
11 ms |
1408 KB |
Output is correct |
7 |
Correct |
256 ms |
26104 KB |
Output is correct |
8 |
Correct |
0 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
256 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 |
1436 KB |
Output is correct |
13 |
Correct |
245 ms |
26104 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
1024 KB |
Output is correct |
17 |
Correct |
123 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 |
62 ms |
6776 KB |
Output is correct |
21 |
Correct |
248 ms |
26104 KB |
Output is correct |
22 |
Correct |
245 ms |
26104 KB |
Output is correct |
23 |
Correct |
260 ms |
26104 KB |
Output is correct |
24 |
Correct |
243 ms |
26104 KB |
Output is correct |
25 |
Correct |
102 ms |
16120 KB |
Output is correct |
26 |
Correct |
100 ms |
16120 KB |
Output is correct |
27 |
Correct |
262 ms |
26104 KB |
Output is correct |
28 |
Correct |
241 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 |
1 ms |
384 KB |
Output is correct |
33 |
Correct |
0 ms |
384 KB |
Output is correct |
34 |
Correct |
0 ms |
384 KB |
Output is correct |
35 |
Correct |
0 ms |
384 KB |
Output is correct |
36 |
Correct |
11 ms |
1408 KB |
Output is correct |
37 |
Correct |
251 ms |
26104 KB |
Output is correct |
38 |
Correct |
1 ms |
384 KB |
Output is correct |
39 |
Correct |
1 ms |
256 KB |
Output is correct |
40 |
Correct |
11 ms |
1408 KB |
Output is correct |
41 |
Correct |
260 ms |
26200 KB |
Output is correct |
42 |
Correct |
0 ms |
256 KB |
Output is correct |
43 |
Correct |
0 ms |
256 KB |
Output is correct |
44 |
Correct |
5 ms |
1024 KB |
Output is correct |
45 |
Correct |
126 ms |
16120 KB |
Output is correct |
46 |
Correct |
0 ms |
256 KB |
Output is correct |
47 |
Correct |
1 ms |
256 KB |
Output is correct |
48 |
Correct |
1 ms |
384 KB |
Output is correct |
49 |
Correct |
61 ms |
6776 KB |
Output is correct |
50 |
Correct |
246 ms |
26104 KB |
Output is correct |
51 |
Correct |
247 ms |
26104 KB |
Output is correct |
52 |
Correct |
264 ms |
26232 KB |
Output is correct |
53 |
Correct |
106 ms |
16124 KB |
Output is correct |
54 |
Correct |
106 ms |
16120 KB |
Output is correct |
55 |
Correct |
244 ms |
26104 KB |
Output is correct |
56 |
Correct |
260 ms |
26236 KB |
Output is correct |
57 |
Correct |
102 ms |
16092 KB |
Output is correct |
58 |
Correct |
1 ms |
256 KB |
Output is correct |
59 |
Correct |
1 ms |
256 KB |
Output is correct |
60 |
Correct |
5 ms |
768 KB |
Output is correct |
61 |
Correct |
107 ms |
12152 KB |
Output is correct |
62 |
Correct |
1 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 |
Incorrect |
24 ms |
3328 KB |
Answer gives possible 0 while actual possible 1 |
66 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
11 ms |
1408 KB |
Output is correct |
7 |
Correct |
256 ms |
26104 KB |
Output is correct |
8 |
Correct |
0 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
256 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 |
1436 KB |
Output is correct |
13 |
Correct |
245 ms |
26104 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
1024 KB |
Output is correct |
17 |
Correct |
123 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 |
62 ms |
6776 KB |
Output is correct |
21 |
Correct |
248 ms |
26104 KB |
Output is correct |
22 |
Correct |
245 ms |
26104 KB |
Output is correct |
23 |
Correct |
260 ms |
26104 KB |
Output is correct |
24 |
Correct |
243 ms |
26104 KB |
Output is correct |
25 |
Correct |
102 ms |
16120 KB |
Output is correct |
26 |
Correct |
100 ms |
16120 KB |
Output is correct |
27 |
Correct |
262 ms |
26104 KB |
Output is correct |
28 |
Correct |
241 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 |
1 ms |
384 KB |
Output is correct |
33 |
Correct |
0 ms |
384 KB |
Output is correct |
34 |
Correct |
0 ms |
384 KB |
Output is correct |
35 |
Correct |
0 ms |
384 KB |
Output is correct |
36 |
Correct |
11 ms |
1408 KB |
Output is correct |
37 |
Correct |
251 ms |
26104 KB |
Output is correct |
38 |
Correct |
1 ms |
384 KB |
Output is correct |
39 |
Correct |
1 ms |
256 KB |
Output is correct |
40 |
Correct |
11 ms |
1408 KB |
Output is correct |
41 |
Correct |
260 ms |
26200 KB |
Output is correct |
42 |
Correct |
0 ms |
256 KB |
Output is correct |
43 |
Correct |
0 ms |
256 KB |
Output is correct |
44 |
Correct |
5 ms |
1024 KB |
Output is correct |
45 |
Correct |
126 ms |
16120 KB |
Output is correct |
46 |
Correct |
0 ms |
256 KB |
Output is correct |
47 |
Correct |
1 ms |
256 KB |
Output is correct |
48 |
Correct |
1 ms |
384 KB |
Output is correct |
49 |
Correct |
61 ms |
6776 KB |
Output is correct |
50 |
Correct |
246 ms |
26104 KB |
Output is correct |
51 |
Correct |
247 ms |
26104 KB |
Output is correct |
52 |
Correct |
264 ms |
26232 KB |
Output is correct |
53 |
Correct |
106 ms |
16124 KB |
Output is correct |
54 |
Correct |
106 ms |
16120 KB |
Output is correct |
55 |
Correct |
244 ms |
26104 KB |
Output is correct |
56 |
Correct |
260 ms |
26236 KB |
Output is correct |
57 |
Correct |
102 ms |
16092 KB |
Output is correct |
58 |
Correct |
1 ms |
256 KB |
Output is correct |
59 |
Correct |
1 ms |
256 KB |
Output is correct |
60 |
Correct |
0 ms |
384 KB |
Output is correct |
61 |
Correct |
61 ms |
6776 KB |
Output is correct |
62 |
Correct |
249 ms |
26104 KB |
Output is correct |
63 |
Correct |
242 ms |
26104 KB |
Output is correct |
64 |
Correct |
274 ms |
26232 KB |
Output is correct |
65 |
Correct |
1 ms |
384 KB |
Output is correct |
66 |
Correct |
61 ms |
6776 KB |
Output is correct |
67 |
Correct |
246 ms |
25976 KB |
Output is correct |
68 |
Correct |
243 ms |
25976 KB |
Output is correct |
69 |
Correct |
261 ms |
26104 KB |
Output is correct |
70 |
Correct |
1 ms |
256 KB |
Output is correct |
71 |
Correct |
0 ms |
384 KB |
Output is correct |
72 |
Incorrect |
1 ms |
256 KB |
Answer gives possible 0 while actual possible 1 |
73 |
Halted |
0 ms |
0 KB |
- |