Submission #303963

# Submission time Handle Problem Language Result Execution time Memory
303963 2020-09-20T20:34:51 Z ignaciocanta Connecting Supertrees (IOI20_supertrees) C++14
30 / 100
272 ms 22136 KB
#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

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
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 10 ms 1152 KB Output is correct
7 Correct 234 ms 22136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 10 ms 1152 KB Output is correct
7 Correct 234 ms 22136 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 360 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 10 ms 1280 KB Output is correct
13 Correct 252 ms 22108 KB Output is correct
14 Incorrect 0 ms 256 KB Answer gives possible 1 while actual possible 0
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 10 ms 1280 KB Output is correct
9 Correct 245 ms 22108 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 416 KB Output is correct
12 Correct 16 ms 1152 KB Output is correct
13 Correct 252 ms 22136 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 6 ms 768 KB Output is correct
17 Correct 125 ms 12152 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 0 ms 256 KB Output is correct
21 Correct 60 ms 5880 KB Output is correct
22 Correct 251 ms 22136 KB Output is correct
23 Correct 246 ms 22104 KB Output is correct
24 Correct 258 ms 22116 KB Output is correct
25 Correct 124 ms 12260 KB Output is correct
26 Correct 135 ms 12252 KB Output is correct
27 Correct 239 ms 22136 KB Output is correct
28 Correct 272 ms 22136 KB Output is correct
29 Correct 104 ms 12152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Incorrect 1 ms 256 KB Too few ways to get from 1 to 2, should be 1 found 0
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 10 ms 1152 KB Output is correct
7 Correct 234 ms 22136 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 360 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 10 ms 1280 KB Output is correct
13 Correct 252 ms 22108 KB Output is correct
14 Incorrect 0 ms 256 KB Answer gives possible 1 while actual possible 0
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 10 ms 1152 KB Output is correct
7 Correct 234 ms 22136 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 360 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 10 ms 1280 KB Output is correct
13 Correct 252 ms 22108 KB Output is correct
14 Incorrect 0 ms 256 KB Answer gives possible 1 while actual possible 0
15 Halted 0 ms 0 KB -