Submission #794204

# Submission time Handle Problem Language Result Execution time Memory
794204 2023-07-26T10:43:46 Z MODDI Connecting Supertrees (IOI20_supertrees) C++14
11 / 100
152 ms 23996 KB
#include "supertrees.h"
#include <bits/stdc++.h>
//#include "grader.cpp"
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
struct DSU{
	vi parent, size;
	void init(int n){
		for(int i = 0; i < n; i++){
			parent.pb(i);
			size.pb(1);
		}
	}
	int find_parent(int v){
		if(parent[v] == v)	return v;
		return parent[v] = find_parent(parent[v]);
	}
	void merge(int a, int b){
		a = find_parent(a);
		b = find_parent(b);
		if(a != b){
			if(size[b] > size[a])
				swap(a, b);
				
			parent[b] = a;
			size[a] += size[b];
		}
	}
};
int construct(vector<vi> p) {
	int n = p.size();
	vector<vi> answer;
	bool possible = true;
	for(int i = 0; i < n; i++){
		for(auto t : p[i]){
			if(t == 3)	possible = false;
		}
	}
	for(int i = 0; i < n; i++){
		vi pom(n,0);
		answer.pb(pom);
	}
	DSU dsu;
	dsu.init(n);
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			if(i == j)	continue;
			if(p[i][j] == 1){
				dsu.merge(i, j);
			}
		}
	}
	int last[n];
	memset(last, -1, sizeof last);
	for(int i = 0; i < n; i++){
		int a = dsu.find_parent(i);
		if(last[a] == -1)	last[a] = i;
		else{
			answer[i][last[a]] = 1;
			answer[last[a]][i] = 1;
			last[a] = i;
		}
	}
	if(!possible)	return 0;
	build(answer);
	return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 232 KB Output is correct
6 Correct 7 ms 1236 KB Output is correct
7 Correct 152 ms 23996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 232 KB Output is correct
6 Correct 7 ms 1236 KB Output is correct
7 Correct 152 ms 23996 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 300 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 6 ms 1236 KB Output is correct
13 Correct 148 ms 23936 KB Output is correct
14 Incorrect 1 ms 212 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 212 KB Output is correct
2 Correct 0 ms 296 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 1 ms 296 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 212 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 212 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 232 KB Output is correct
6 Correct 7 ms 1236 KB Output is correct
7 Correct 152 ms 23996 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 300 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 6 ms 1236 KB Output is correct
13 Correct 148 ms 23936 KB Output is correct
14 Incorrect 1 ms 212 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 212 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 232 KB Output is correct
6 Correct 7 ms 1236 KB Output is correct
7 Correct 152 ms 23996 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 300 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 6 ms 1236 KB Output is correct
13 Correct 148 ms 23936 KB Output is correct
14 Incorrect 1 ms 212 KB Answer gives possible 1 while actual possible 0
15 Halted 0 ms 0 KB -