This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "supertrees.h"
#include <vector>
#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define pb push_back
using namespace std;
const int N = 1e3+5;
vector<int>c[N];
int cnt = 0, n;
int fix[N];
vector<int>chain;
void dfs(int x,vector<vector<int>>&p){
fix[x] = 1;
//cout << x << endl;
c[cnt].pb(x);
for(int i = 0; i < n; i++){
if(fix[i]) continue;
if(p[x][i]){
dfs(i,p);
}
}
}
void dfs1(int x,vector<vector<int>>&p){
fix[x] = 1;
//c[cnt].pb(x);
chain.pb(x);
//cout << x << endl;
for(int i = 0; i < n; i++){
//cout << fix[i] << " ";
if(fix[i]) continue;
if(p[x][i] == 1){
dfs1(i,p);
}
}
//cout << endl;
}
bool check(vector<int>&v, vector<vector<int>>&p){
for(int i = 0; i < (int)v.size(); i++){
for(int j = 0; j < (int)v.size(); j++){
if(p[v[i]][v[j]] == 2){
return 0;
}
}
}
return 1;
}
void cr(int x,int y,vector<vector<int>>&v){
v[x][y] = 1;
v[y][x] = 1;
}
int construct(std::vector<std::vector<int>> p) {
n = p.size();
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(p[i][j] == 3){
return 0;
}
}
}
for(int i = 0; i < n; i++){
if(fix[i]) continue;
cnt++;//cout << i << endl;
dfs(i,p);
}
for(int i = 0; i < n; i++) fix[i] = 0;
for(int i = 1; i <= cnt; i++){
for(int j = 0; j < c[i].size(); j++){
for(int t = 0; t < c[i].size(); t++){
if(p[c[i][j]][c[i][t]] == 0){
return 0;
}
}
}
}
vector<vector<int>>answer(n,vector<int>(n,0));
vector<int>cyc;
for(int i = 1; i <= cnt; i++){
for(int j = 0; j < c[i].size(); j++){
int x = c[i][j];
if(fix[x]) continue;
chain.clear();
dfs1(x,p);
if(check(chain,p) == 0){
return 0;
}
for(int t = 0; t+1 < chain.size(); t++){
int x = chain[t];
int y = chain[t+1];
cr(x,y,answer);
}
cyc.pb(chain[0]);
}
if(cyc.size() == 2) return 0;
if(cyc.size() > 1)
for(int i = 0; i < cyc.size(); i++){
int x = cyc[i];
int y = cyc[(i+1)%(int)cyc.size()];
cr(x,y,answer);
}
cyc.clear();
}
build(answer);
return 1;
}
Compilation message (stderr)
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:81:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
81 | for(int j = 0; j < c[i].size(); j++){
| ~~^~~~~~~~~~~~~
supertrees.cpp:82:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
82 | for(int t = 0; t < c[i].size(); t++){
| ~~^~~~~~~~~~~~~
supertrees.cpp:93:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
93 | for(int j = 0; j < c[i].size(); j++){
| ~~^~~~~~~~~~~~~
supertrees.cpp:101:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
101 | for(int t = 0; t+1 < chain.size(); t++){
| ~~~~^~~~~~~~~~~~~~
supertrees.cpp:110:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
110 | for(int i = 0; i < cyc.size(); i++){
| ~~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |