#include <bits/stdc++.h>
#include "supertrees.h"
#define all(a) a.begin(),a.end()
using namespace std;
const int mxn= 1e3+1 ;
vector<int> adj[mxn] , adjj[mxn] , one , mn ;
void dfs(int i , vector<int>& a ){
a[i]=1 ;
for(int& x : adj[i]){
if(a[x]) continue ;
dfs(x,a) ;
}
}
void dfss(int i , vector<int>& a){
a[i] = 1 ;
if(adjj[i].size()==1) one.push_back(i) ;
for(int& x : adjj[i]){
if(a[x]) continue ;
dfss(x,a) ;
}
}
vector<vector<int>> pp ;
bool check(int i , vector<int>& a){
a[i] =1 ;
for(int j=0;j<mn.size();j++){
if(pp[i][j]==2&&mn[j]!=2) return 1 ;
if(mn[j]==2&&pp[i][j]!=2) return 1 ;
}
bool b = 0 ;
for(int& x : adj[i]){
if(a[x]) continue ;
b|=check(x,a) ;
}
return b ;
}
int construct(vector<vector<int>> p){
pp = p ;
int n =p.size() ;
vector<int> the(n) ;
for(int i=0;i<n;i++){
bool flg = 0 ;
vector<int> x=p[i] ;
for(int j=0;j<i;j++){
if(x[j]==1){
adj[i].push_back(j) ;
flg = 1 ;
break ;
}
}
if(flg) continue ;
//cout <<i << endl ;
the[i] =1 ;
for(int j=i+1;j<n;j++) if(x[j]==1) adj[i].push_back(j) ;
}
for(int i=0;i<n;i++){
vector<int> vis(n) ;
dfs(i,vis) ;
for(int j=0;j<n;j++){
if(vis[j]==1&&p[i][j]==1) continue ;
if(vis[j]==0&&p[i][j]==0) continue ;
if(p[i][j]==2&&vis[j]==0) continue ;
return 0 ;
}
}
for(int i=0;i<n;i++){
if(the[i]==0) continue ;
for(int j=i-1;j>-1;j--){
if(the[j]==0) continue ;
if(p[i][j]==2){
adjj[i].push_back(j) ;
break ;
}
}
for(int j=i+1;j<n;j++){
if(the[j]==0) continue ;
if(p[i][j]==2){
adjj[i].push_back(j) ;
break ;
}
}
}
vector<int> vis(n);
map<vector<int>,int> pp ;
for(int i=0;i<n;i++){
if(the[i]==0) continue ;
one.erase(one.begin(),one.end()) ;
dfss(i,vis) ;
sort(all(one)) ;
for(int j=0;j<n;j++){
if(i==j) continue ;
if(the[j]==0) continue ;
if(vis[i]==1&&p[i][j]==2) continue ;
if(vis[i]==0&&p[i][j]==0) continue ;
if(vis[i]==0&&p[i][j]==1) continue ;
//cout << i << " " << j << endl ;
return 0 ;
}
if(one.size()==1) continue ;
if(one.size()==2) return 0 ;
if(pp[one]) continue ;
pp[one]=1 ;
adjj[one.back()].push_back(one[0]) ;
adjj[one[0]].push_back(one.back()) ;
}
/*vector<int> viss(n) ;
for(int i=0;i<n;i++){
if(viss[i]==1) continue ;
mn = p[i] ;
bool f = check(i,viss) ;
if(f) return 0 ;
}*/
vector<vector<int>> ans ;
for(int i=0;i<n;i++) for(int& x : adjj[i]) adj[i].push_back(x) ;
for(int i=0;i<n;i++){
vector<int> row(n) ;
for(int& x : adj[i]) row[x]= 1 ;
ans.push_back(row) ;
}
build(ans) ;
return 1 ;
}
Compilation message
supertrees.cpp: In function 'bool check(int, std::vector<int>&)':
supertrees.cpp:25:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for(int j=0;j<mn.size();j++){
| ~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
512 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
512 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Answer gives possible 0 while actual possible 1 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Answer gives possible 0 while actual possible 1 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
512 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
512 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |