Submission #303953

#TimeUsernameProblemLanguageResultExecution timeMemory
303953ignaciocantaConnecting Supertrees (IOI20_supertrees)C++14
Compilation error
0 ms0 KiB
#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"

static int n;
static std::vector<std::vector<int>> p;
static std::vector<std::vector<int>> b;
static bool called = false;

static void check(bool cond, std::string message) {
    if (!cond) {
        printf("%s\n", message.c_str());
        fclose(stdout);
        exit(0);
    }
}

void build(std::vector<std::vector<int>> _b) {
    check(!called, "build is called more than once");
    called = true;
    check((int)_b.size() == n, "Invalid number of rows in b");
    for (int i = 0; i < n; i++) {
        check((int)_b[i].size() == n, "Invalid number of columns in b");
    }
    b = _b;
}

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;
	forn(i, n){
		forn(j, n){
			if(p[i][j] == 3) ok = 0;
		}
	}
	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 || sz(comps[i]) == 1) ok = 0;
		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);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/ccFWLtGy.o: In function `build(std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >)':
grader.cpp:(.text+0x1d0): multiple definition of `build(std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >)'
/tmp/ccA7SG6M.o:supertrees.cpp:(.text+0x3c0): first defined here
collect2: error: ld returned 1 exit status