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 <bits/stdc++.h>
using namespace std;
using tint = long long;
using ld = long double;
#define forsn(i, s, n) for(int i = s; i < int(n); i++)
#define forn(i, n) forsn(i, 0, n)
using vi = vector<int>;
#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using pi = pair<int,int>;
#define f first
#define s second
#define mp make_pair
#define DBG(x) cerr << #x << " = " << x << endl;
const int MOD = 1e9+7;
const int MX = 1000005;
const int INF = 1e9;
const ld PI = acos(ld(-1));
void NACHO(string name = "rental"){
ios_base::sync_with_stdio(0); cin.tie(0);
freopen((name+".in").c_str(), "r", stdin);
freopen((name+".out").c_str(), "w", stdout);
}
#include "supertrees.h"
vi parent (1001);
vi size (1001);
void fill(int n){
forn(i, n){
size[i] = 1;
parent[i] = i;
}
}
int find(int x){
if(x == parent[x]) return x;
return parent[x] = find(parent[x]);
}
void unite(int a, int b){
a = find(a);
b = find(b);
if(a != b){
if(size[a] < size[b]) swap(a, b);
parent[b] = a;
size[a]+=size[b];
}
}
int construct(std::vector<std::vector<int>> p) {
//Primero, si hay un 3, es imposible
//(Al menos no encontre un caso que rompiera, ya que siempre implica que hay un camino mas largo)
int n = sz(p);
bool ok = 1;
bool subtask1 = 1;
forn(i, n){
forn(j, n){
if(p[i][j] == 3) ok = 0;
if(p[i][j] != 1) subtask1 = 0;
}
}
if(subtask1){
vector<vi> g (n, vi (n, 0));
forn(i, n-1){
g[i][i+1] = g[i+1][i] = 1;
}
build(g);
return 1;
}
fill(n);
forn(i, n){
forn(j, n){
if(p[i][j] == 2){
unite(i, j);
}
}
}
forn(i, n){
forn(j, n){
if(p[i][j] == 0){
if(find(i) == find(j)) ok = 0;
}
}
}
vector<vi> g (n, vi (n, 0));
vector<vi> comps (n);
forn(i, n){
comps[find(i)].pb(i);
}
forn(i, n){
if(sz(comps[i]) == 2) ok = 0;
if(sz(comps[i]) == 1) continue;
forn(j, sz(comps[i])){
g[comps[i][j]][comps[i][(j+1)%sz(comps[i])]] = g[comps[i][(j+1)%sz(comps[i])]][comps[i][j]] = 1;
}
}
if(!ok){
return 0;
}
build(g);
return 1;
}
Compilation message (stderr)
supertrees.cpp: In function 'void NACHO(std::string)':
supertrees.cpp:31:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
31 | freopen((name+".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
supertrees.cpp:32:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
32 | freopen((name+".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |