Submission #1034209

# Submission time Handle Problem Language Result Execution time Memory
1034209 2024-07-25T10:37:46 Z Gray Connecting Supertrees (IOI20_supertrees) C++17
0 / 100
1 ms 348 KB
#include "supertrees.h"
#include <map>
#include <vector>

using namespace std;

#define ll long long
#define ff first
#define ss second
#define ln "\n"
#define pll pair<ll, ll>

struct DSU{
	vector<ll> p;
	ll n;
	DSU(ll N){
		n=N;
		p.resize(n, -1);
	}
	ll get(ll x){
		return p[x]==-1?x:p[x]=get(p[x]);
	}
	bool unite(ll a, ll b){
		a=get(a);
		b=get(b);
		if (a==b) return 0;
		p[a]=b;
		return 1;
	}
};

int construct(std::vector<std::vector<int>> p) {
	int n = (int)p.size();
	DSU tr(n);
	vector<vector<int>> A(n);
	for (int i=0; i<n; i++){
		for (int j=0; j<n; j++){
			if (i!=j and p[i][j]==2){
				tr.unite(i, j);
			}
		}
	}
	for (int i=0; i<n; i++){
		for (int j=0; j<n; j++){
			if (i!=j and p[i][j]==0 and tr.get(i)==tr.get(j)){
				return 0;
			}
		}
	}
	map<ll, vector<ll>> cc;
	for (ll i=0; i<n; i++){
		cc[tr.get(i)].push_back(i);
	}
	vector<vector<int>> ans(n, vector<int>(n, 0));
	for (auto &[comp, mem]:cc){
		if (mem.size()<=2){
			return 0;
		}
		for (ll i=0; i<(ll)mem.size(); i++){
			ll nxt=(i+1)%(ll)(mem.size()), nxt2=(i+2)%(ll)(mem.size());
			ans[mem[i]][mem[nxt]]=ans[mem[i]][mem[nxt2]]=ans[mem[nxt]][mem[i]]=ans[mem[nxt2]][mem[i]]=1;
		}
	}
	build(ans);
	return 1;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Answer gives possible 0 while actual possible 1
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Answer gives possible 0 while actual possible 1
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Answer gives possible 0 while actual possible 1
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Answer gives possible 0 while actual possible 1
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Answer gives possible 0 while actual possible 1
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Answer gives possible 0 while actual possible 1
2 Halted 0 ms 0 KB -