#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 ;
}
}
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 ;
//(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++){
| ~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Incorrect |
0 ms |
288 KB |
b is not symmetric: b[1][2] (0) != b[2][1] (1) |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Incorrect |
0 ms |
288 KB |
b is not symmetric: b[1][2] (0) != b[2][1] (1) |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
416 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Incorrect |
0 ms |
384 KB |
Answer gives possible 1 while actual possible 0 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Incorrect |
1 ms |
384 KB |
Too few ways to get from 0 to 1, should be 2 found 0 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Incorrect |
0 ms |
288 KB |
b is not symmetric: b[1][2] (0) != b[2][1] (1) |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Incorrect |
0 ms |
288 KB |
b is not symmetric: b[1][2] (0) != b[2][1] (1) |
4 |
Halted |
0 ms |
0 KB |
- |