#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;
//for(int i=0;i<nn;i++)
//if(g[start][i]!=g[beg][i] && i!=start && i!=beg)
// return 0;
//ll count=0;
//for(int i=0;i<nn;i++)
//if(g[start][i]==2)
//count++;
//if(count==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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1340 KB |
Output is correct |
7 |
Correct |
180 ms |
25984 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1340 KB |
Output is correct |
7 |
Correct |
180 ms |
25984 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
8 ms |
1236 KB |
Output is correct |
13 |
Correct |
220 ms |
25996 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
952 KB |
Output is correct |
17 |
Correct |
96 ms |
16840 KB |
Output is correct |
18 |
Correct |
2 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
79 ms |
7240 KB |
Output is correct |
21 |
Correct |
200 ms |
26716 KB |
Output is correct |
22 |
Correct |
195 ms |
26840 KB |
Output is correct |
23 |
Correct |
224 ms |
26724 KB |
Output is correct |
24 |
Correct |
217 ms |
26760 KB |
Output is correct |
25 |
Correct |
86 ms |
16940 KB |
Output is correct |
26 |
Correct |
74 ms |
16828 KB |
Output is correct |
27 |
Correct |
188 ms |
26784 KB |
Output is correct |
28 |
Correct |
212 ms |
26744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
Incorrect |
0 ms |
212 KB |
Answer gives possible 1 while actual possible 0 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
49 ms |
6680 KB |
Output is correct |
5 |
Correct |
189 ms |
25928 KB |
Output is correct |
6 |
Correct |
187 ms |
25884 KB |
Output is correct |
7 |
Correct |
192 ms |
25984 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
48 ms |
6716 KB |
Output is correct |
10 |
Correct |
204 ms |
26052 KB |
Output is correct |
11 |
Correct |
206 ms |
25924 KB |
Output is correct |
12 |
Correct |
203 ms |
25988 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
51 ms |
6672 KB |
Output is correct |
17 |
Correct |
225 ms |
25980 KB |
Output is correct |
18 |
Correct |
199 ms |
25980 KB |
Output is correct |
19 |
Correct |
202 ms |
25912 KB |
Output is correct |
20 |
Correct |
185 ms |
25968 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1340 KB |
Output is correct |
7 |
Correct |
180 ms |
25984 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
8 ms |
1236 KB |
Output is correct |
13 |
Correct |
220 ms |
25996 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
952 KB |
Output is correct |
17 |
Correct |
96 ms |
16840 KB |
Output is correct |
18 |
Correct |
2 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
79 ms |
7240 KB |
Output is correct |
21 |
Correct |
200 ms |
26716 KB |
Output is correct |
22 |
Correct |
195 ms |
26840 KB |
Output is correct |
23 |
Correct |
224 ms |
26724 KB |
Output is correct |
24 |
Correct |
217 ms |
26760 KB |
Output is correct |
25 |
Correct |
86 ms |
16940 KB |
Output is correct |
26 |
Correct |
74 ms |
16828 KB |
Output is correct |
27 |
Correct |
188 ms |
26784 KB |
Output is correct |
28 |
Correct |
212 ms |
26744 KB |
Output is correct |
29 |
Correct |
1 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 |
Incorrect |
0 ms |
212 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1340 KB |
Output is correct |
7 |
Correct |
180 ms |
25984 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
8 ms |
1236 KB |
Output is correct |
13 |
Correct |
220 ms |
25996 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
952 KB |
Output is correct |
17 |
Correct |
96 ms |
16840 KB |
Output is correct |
18 |
Correct |
2 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
79 ms |
7240 KB |
Output is correct |
21 |
Correct |
200 ms |
26716 KB |
Output is correct |
22 |
Correct |
195 ms |
26840 KB |
Output is correct |
23 |
Correct |
224 ms |
26724 KB |
Output is correct |
24 |
Correct |
217 ms |
26760 KB |
Output is correct |
25 |
Correct |
86 ms |
16940 KB |
Output is correct |
26 |
Correct |
74 ms |
16828 KB |
Output is correct |
27 |
Correct |
188 ms |
26784 KB |
Output is correct |
28 |
Correct |
212 ms |
26744 KB |
Output is correct |
29 |
Correct |
1 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 |
Incorrect |
0 ms |
212 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |