#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define F first
#define S second
#define enter cout<<'\n';
#define INF 99999999999999999
#define MOD 1000000007
#define all(x) x.begin(),x.end()
vector<bool>vis(1000,0);
vector<bool>vis2(1000,0);
vector<vector<int>>g;
vector<vector<int>>ans;
ll nn;
bool dfs1(int start,int beg)
{
vis[start]=1;
for(int i=0;i<nn;i++)
if(g[start][i]!=g[beg][i] && i!=start && i!=beg)
return 0;
for(int i=0;i<nn;i++)
if(!vis[i] && g[start][i]==1)
{
ans[i][start]=1;
ans[start][i]=1;
return dfs1(i,beg);
}
vis[beg]=0;
return 1;
}
bool dfs2(int start,int beg)
{
vis[start]=1;
if(start!=beg)
for(int i=0;i<nn;i++)
{
if(g[start][i]==1 && g[beg][i]==1)
return 0;
if(g[start][i]==2 && g[beg][i]==0 || g[start][i]==0 && g[beg][i]==2)
return 0;
if(g[start][i]==1 && g[beg][i]==0 || g[start][i]==0 && g[beg][i]==1)
return 0;
}
ll count=0;
for(int i=0;i<nn;i++)
if(g[start][i]==2 && !vis[i])
count++;
if(count==1)
{
assert(0);
assert(1);
return 0;
}
for(int i=0;i<nn;i++)
if(!vis[i] && g[start][i]==2)
{
ans[i][start]=1;
ans[start][i]=1;
return dfs2(i,beg);
}
ans[start][beg]=1;
ans[beg][start]=1;
return 1;
}
int construct(vector<vector<int>> pr)
{
nn=pr.size();
g=pr;
ans.assign(nn,vector<int>(nn,0));
for(int i=0;i<nn;i++)
{
bool now=dfs1(i,i);
if(!now)
return 0;
}
for(int i=0;i<nn;i++)
{
if(vis[i])
continue;
bool now=dfs2(i,i);
if(!now)
return 0;
}
for(int i=0;i<nn;i++)
ans[i][i]=0;
build(ans);
return 1;
}
Compilation message
supertrees.cpp: In function 'bool dfs2(int, int)':
supertrees.cpp:50:21: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
50 | if(g[start][i]==2 && g[beg][i]==0 || g[start][i]==0 && g[beg][i]==2)
supertrees.cpp:53:21: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
53 | if(g[start][i]==1 && g[beg][i]==0 || g[start][i]==0 && g[beg][i]==1)
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1236 KB |
Output is correct |
7 |
Correct |
179 ms |
25980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1236 KB |
Output is correct |
7 |
Correct |
179 ms |
25980 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1236 KB |
Output is correct |
13 |
Correct |
170 ms |
25892 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
852 KB |
Output is correct |
17 |
Correct |
96 ms |
16032 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
43 ms |
6756 KB |
Output is correct |
21 |
Correct |
209 ms |
26068 KB |
Output is correct |
22 |
Correct |
168 ms |
26004 KB |
Output is correct |
23 |
Correct |
196 ms |
25872 KB |
Output is correct |
24 |
Correct |
168 ms |
26060 KB |
Output is correct |
25 |
Correct |
76 ms |
16020 KB |
Output is correct |
26 |
Correct |
67 ms |
16104 KB |
Output is correct |
27 |
Correct |
179 ms |
25904 KB |
Output is correct |
28 |
Correct |
177 ms |
25988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 6 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1236 KB |
Output is correct |
7 |
Correct |
179 ms |
25980 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1236 KB |
Output is correct |
13 |
Correct |
170 ms |
25892 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
852 KB |
Output is correct |
17 |
Correct |
96 ms |
16032 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
43 ms |
6756 KB |
Output is correct |
21 |
Correct |
209 ms |
26068 KB |
Output is correct |
22 |
Correct |
168 ms |
26004 KB |
Output is correct |
23 |
Correct |
196 ms |
25872 KB |
Output is correct |
24 |
Correct |
168 ms |
26060 KB |
Output is correct |
25 |
Correct |
76 ms |
16020 KB |
Output is correct |
26 |
Correct |
67 ms |
16104 KB |
Output is correct |
27 |
Correct |
179 ms |
25904 KB |
Output is correct |
28 |
Correct |
177 ms |
25988 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 6 |
33 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1236 KB |
Output is correct |
7 |
Correct |
179 ms |
25980 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1236 KB |
Output is correct |
13 |
Correct |
170 ms |
25892 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
852 KB |
Output is correct |
17 |
Correct |
96 ms |
16032 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
43 ms |
6756 KB |
Output is correct |
21 |
Correct |
209 ms |
26068 KB |
Output is correct |
22 |
Correct |
168 ms |
26004 KB |
Output is correct |
23 |
Correct |
196 ms |
25872 KB |
Output is correct |
24 |
Correct |
168 ms |
26060 KB |
Output is correct |
25 |
Correct |
76 ms |
16020 KB |
Output is correct |
26 |
Correct |
67 ms |
16104 KB |
Output is correct |
27 |
Correct |
179 ms |
25904 KB |
Output is correct |
28 |
Correct |
177 ms |
25988 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 6 |
33 |
Halted |
0 ms |
0 KB |
- |