#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define INF 1e18
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define OK cout<<"Ok"<<endl;
#define MOD (ll)(1e9+7)
const int mxn=1e3+5;
int n,color[mxn],k,color2[mxn],sz,lst,arr[mxn][mxn];
vector<int>vt[mxn];
vector<int>vt2[mxn];
vector<vector<int>>p;
void dfs(int u){
color[u]=k;
sz++;
for(int v:vt[u]){
if(!color[v]){
arr[u][v]=1;
arr[v][u]=1;
dfs(v);
}
}
}
void dfs2(int u){
color2[u]=k;
sz++;
lst=u;
for(int v:vt[u]){
if(!color[v]&&!color2[v]){
arr[u][v]=1;
arr[v][u]=1;
dfs2(v);
}
}
}
int construct(vector<vector<int>> pp) {
p=pp;
n=p.size();
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
if(p[i][j]==1){
vt[i+1].pb(j+1);
vt[j+1].pb(i+1);
}
else if(p[i][j]==2){
vt[i+1].pb(j+1);
vt[j+1].pb(i+1);
}
else if(p[i][j]==3){
return 0;
}
}
}
for(int i=1;i<=n;i++){
if(!color[i]){
k=i;
sz=0;
dfs(i);
if(sz==1){
color[i]=0;
}
}
}
for(int i=1;i<=n;i++){
for(int j=i+1;j<=n;j++){
if(color[i]>0&&color[i]==color[j]&&p[i-1][j-1]!=1){
return 0;
}
}
}
vector<pii>v;
for(int i=1;i<=n;i++){
if(color[i]) continue;
k=i;
sz=0;
dfs2(i);
if(lst==i){
color2[i]=0;
}
else{
arr[i][lst]=1;
arr[lst][i]=1;
v.pb({i,lst});
}
}
for(int i=1;i<=n;i++){
for(int j=i+1;j<=n;j++){
if(color2[i]>0&&color2[i]==color2[j]&&p[i-1][j-1]!=2){
return 0;
}
}
}
for(int i=1;i<=n;i++){
for(int j=i+1;j<=n;j++){
if(p[i-1][j-1]==2&&!(color2[i]&&color2[j])){
if(color2[i]){
int a=color2[i],b=color[j];
arr[a][b]=1;
arr[b][a]=1;
}
else{
int a=color[i],b=color2[j];
arr[a][b]=1;
arr[b][a]=1;
}
}
}
}
vector<vector<int>>ans;
for(int i=1;i<=n;i++){
vector<int>vt;
for(int j=1;j<=n;j++){
vt.pb(arr[i][j]);
}
ans.pb(vt);
}
build(ans);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
7 ms |
2388 KB |
Output is correct |
7 |
Correct |
157 ms |
34120 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
7 ms |
2388 KB |
Output is correct |
7 |
Correct |
157 ms |
34120 KB |
Output is correct |
8 |
Correct |
0 ms |
388 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
7 ms |
1368 KB |
Output is correct |
13 |
Correct |
161 ms |
26060 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
3 ms |
1748 KB |
Output is correct |
17 |
Correct |
70 ms |
18876 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
41 ms |
8636 KB |
Output is correct |
21 |
Correct |
154 ms |
30500 KB |
Output is correct |
22 |
Correct |
155 ms |
29628 KB |
Output is correct |
23 |
Correct |
160 ms |
32028 KB |
Output is correct |
24 |
Correct |
151 ms |
26272 KB |
Output is correct |
25 |
Correct |
63 ms |
16572 KB |
Output is correct |
26 |
Correct |
69 ms |
15672 KB |
Output is correct |
27 |
Correct |
173 ms |
33048 KB |
Output is correct |
28 |
Correct |
151 ms |
26240 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Incorrect |
0 ms |
340 KB |
Answer gives possible 0 while actual possible 1 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Incorrect |
0 ms |
340 KB |
Answer gives possible 0 while actual possible 1 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
7 ms |
2388 KB |
Output is correct |
7 |
Correct |
157 ms |
34120 KB |
Output is correct |
8 |
Correct |
0 ms |
388 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
7 ms |
1368 KB |
Output is correct |
13 |
Correct |
161 ms |
26060 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
3 ms |
1748 KB |
Output is correct |
17 |
Correct |
70 ms |
18876 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
41 ms |
8636 KB |
Output is correct |
21 |
Correct |
154 ms |
30500 KB |
Output is correct |
22 |
Correct |
155 ms |
29628 KB |
Output is correct |
23 |
Correct |
160 ms |
32028 KB |
Output is correct |
24 |
Correct |
151 ms |
26272 KB |
Output is correct |
25 |
Correct |
63 ms |
16572 KB |
Output is correct |
26 |
Correct |
69 ms |
15672 KB |
Output is correct |
27 |
Correct |
173 ms |
33048 KB |
Output is correct |
28 |
Correct |
151 ms |
26240 KB |
Output is correct |
29 |
Correct |
0 ms |
340 KB |
Output is correct |
30 |
Correct |
0 ms |
340 KB |
Output is correct |
31 |
Correct |
0 ms |
340 KB |
Output is correct |
32 |
Correct |
0 ms |
340 KB |
Output is correct |
33 |
Incorrect |
0 ms |
340 KB |
Answer gives possible 0 while actual possible 1 |
34 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
7 ms |
2388 KB |
Output is correct |
7 |
Correct |
157 ms |
34120 KB |
Output is correct |
8 |
Correct |
0 ms |
388 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
7 ms |
1368 KB |
Output is correct |
13 |
Correct |
161 ms |
26060 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
3 ms |
1748 KB |
Output is correct |
17 |
Correct |
70 ms |
18876 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
41 ms |
8636 KB |
Output is correct |
21 |
Correct |
154 ms |
30500 KB |
Output is correct |
22 |
Correct |
155 ms |
29628 KB |
Output is correct |
23 |
Correct |
160 ms |
32028 KB |
Output is correct |
24 |
Correct |
151 ms |
26272 KB |
Output is correct |
25 |
Correct |
63 ms |
16572 KB |
Output is correct |
26 |
Correct |
69 ms |
15672 KB |
Output is correct |
27 |
Correct |
173 ms |
33048 KB |
Output is correct |
28 |
Correct |
151 ms |
26240 KB |
Output is correct |
29 |
Correct |
0 ms |
340 KB |
Output is correct |
30 |
Correct |
0 ms |
340 KB |
Output is correct |
31 |
Correct |
0 ms |
340 KB |
Output is correct |
32 |
Correct |
0 ms |
340 KB |
Output is correct |
33 |
Incorrect |
0 ms |
340 KB |
Answer gives possible 0 while actual possible 1 |
34 |
Halted |
0 ms |
0 KB |
- |