Submission #1015804

# Submission time Handle Problem Language Result Execution time Memory
1015804 2024-07-06T20:23:30 Z XJP12 Connecting Supertrees (IOI20_supertrees) C++14
0 / 100
1000 ms 344 KB
#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
int n;
struct UF{
	vi e;
	UF(int n){ e.resize(n,-1);}

	int find(int x){ return (e[x] > 0 ? x : find(-e[x])); }

	void _union(int a, int b){
		int x = find(a);
		int y = find(b);
		if(x == y) return;
		if(e[x] < e[y]) swap(x,y);
		e[x] += e[y];
		e[y] = -x;
	}
};
int construct(vvi p){
	n = p.size();
	int ban=0;
	UF fu(n);
	vvi ans(n, vi(n,0));
	vvi conect(n, vi());
	for(int i=0; i<n; i++){
		for(int j=i; j<n; j++){
			if(i==j) continue;
			if(p[i][j]==1 && ban==0){
				ban=1;
			}
			if(p[i][j]==2 && ban==0){
				ban=2;
			}
			if(p[i][j]!=0){
				fu._union(i, j);
			}
		}
	}
	for(int i=0; i<n; i++){
		for(int j=i; j<n; j++){
			if(p[i][j]==0){
				if(fu.find(i)==fu.find(j)){
					return 0;
				}
			}else{
				int t = fu.find(i);
				conect[t].push_back(i);
				conect[t].push_back(j);
			}
		}
	}
	for(int i=0; i<n; i++){
		for(int j=0; j<(int)conect.size()-1; j++){
			ans[conect[i][j+1]][conect[i][j]]=1;
			ans[conect[i][j]][conect[i][j+1]]=1;
		}
		if(ban==2){
			ans[conect[i][(int)conect.size()-1]][conect[i][0]]=1;
			ans[conect[i][0]][conect[i][(int)conect.size()-1]]=1;
		}
	}
	build(ans);
	return 1;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 1045 ms 344 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1045 ms 344 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1028 ms 344 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1092 ms 344 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1045 ms 344 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1045 ms 344 KB Time limit exceeded
2 Halted 0 ms 0 KB -