Submission #741757

# Submission time Handle Problem Language Result Execution time Memory
741757 2023-05-14T19:45:57 Z MODDI Connecting Supertrees (IOI20_supertrees) C++14
11 / 100
184 ms 23928 KB
#include "supertrees.h"
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define pb push_back
#define vi vector<int>
using namespace std;
int parent[1001], sz[1001];
void init(){
	for(int i = 0; i < 1000; i++){
		parent[i] = i;
		sz[i] = 1;
	}
}
int find(int v){
	if(parent[v] == v)	return v;
	return parent[v] = find(parent[v]);
}
void combine(int i, int j){
	i = find(i);
	j = find(j);
	if(i == j)	return;
	if(sz[i] < sz[j]) swap(i, j);
	parent[j] = i;
	sz[i] += sz[j];
}
int construct(std::vector<std::vector<int>> p) {
	int n = p.size();
	bool one = true, two = true, lessTwo = true;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			if(p[i][j] == 3)	return 0;
			if(p[i][j]  != one)	one = false;
			if(p[i][j] == 2)	lessTwo = false;
		}
	}
	if(one){
		vector<vector<int>> b;
		for(int i = 0; i < n; i++){
			vi arr(n, 0);
			if(i >0)	arr[i-1]=1;
			if(i+1<n)	arr[i+1]=1;
			b.pb(arr);
		}
		build(b);	
		return 1;	
	}
	else if(lessTwo){
		init();
		for(int i = 0; i < n; i++){
			for(int j = i+1; j < n; j++){
				if(p[i][j] == 1){
					combine(i, j);
				}
			}
		}
		int last[n]; // for every branch;
		memset(last, -1, sizeof last);
		vector<vector<int> > b(n, vector<int>(n));
		for(int i = 0; i < n; i++){
			int prev = last[find(i)];
			if(prev == -1){
				last[find(i)] = i;
			}
			else{
				b[i][prev] = 1;
				b[prev][i] = 1;
				last[find(i)] = i;
			}
		}
		build(b);
		return 1;
	}
	return 0;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:31:19: warning: unused variable 'two' [-Wunused-variable]
   31 |  bool one = true, two = true, lessTwo = true;
      |                   ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 300 KB Output is correct
5 Correct 0 ms 312 KB Output is correct
6 Correct 10 ms 1236 KB Output is correct
7 Correct 184 ms 23928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 300 KB Output is correct
5 Correct 0 ms 312 KB Output is correct
6 Correct 10 ms 1236 KB Output is correct
7 Correct 184 ms 23928 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 308 KB Output is correct
12 Correct 7 ms 1216 KB Output is correct
13 Correct 170 ms 23928 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 304 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Incorrect 1 ms 212 KB Answer gives possible 0 while actual possible 1
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB Output is correct
2 Incorrect 1 ms 232 KB Answer gives possible 0 while actual possible 1
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 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 300 KB Output is correct
5 Correct 0 ms 312 KB Output is correct
6 Correct 10 ms 1236 KB Output is correct
7 Correct 184 ms 23928 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 308 KB Output is correct
12 Correct 7 ms 1216 KB Output is correct
13 Correct 170 ms 23928 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 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 300 KB Output is correct
5 Correct 0 ms 312 KB Output is correct
6 Correct 10 ms 1236 KB Output is correct
7 Correct 184 ms 23928 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 308 KB Output is correct
12 Correct 7 ms 1216 KB Output is correct
13 Correct 170 ms 23928 KB Output is correct
14 Incorrect 1 ms 212 KB Answer gives possible 1 while actual possible 0
15 Halted 0 ms 0 KB -