Submission #1015818

# Submission time Handle Problem Language Result Execution time Memory
1015818 2024-07-06T21:19:21 Z XJP12 Connecting Supertrees (IOI20_supertrees) C++14
0 / 100
0 ms 348 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.assign(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) {ans[i][j]=1; 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[i].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;
		}
	}
  ans[0][0]=1;
	build(ans);
	return 1;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB b[0][0] is not 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB b[0][0] is not 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB b[0][0] is not 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB b[0][0] is not 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB b[0][0] is not 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB b[0][0] is not 0
2 Halted 0 ms 0 KB -