Submission #563134

# Submission time Handle Problem Language Result Execution time Memory
563134 2022-05-16T11:04:31 Z Aktan Swapping Cities (APIO20_swap) C++14
0 / 100
98 ms 11832 KB
#include "swap.h"
#include <bits/stdc++.h>
using namespace std;

#ifndef EVAL
#include "grader.cpp"
#endif

struct DSU{
	vector<int> p;
	vector<int> mx;
	DSU(int n) : p(n),mx(n){
		for(int i=0;i<n;i++){
			p[i]=i;
			mx[i]=0;
		}
	}
	int find(int x){
		if(p[x]==x){
			return x;
		}
		else{
			return p[x]=find(p[x]);
		}
	}
	void merge(int x,int y){
		int a=find(x),b=find(y);
		if(a==b){
			return;
		}
		else{
			mx[b]=max(mx[b],mx[a]);
			p[a]=b;
			return;
		}
	}
};
vector<int> e[100005];
int used[100005],ans[100005];
DSU dsu(100005);
bool h=0;
void dfs(int x){
	used[x]++;
	if(e[x].size()<2){
		h=1;
		return;
	}
	if(h==1){
		return;
	}
	for(auto w : e[x]){
		if(used[w]==0){
			dfs(w);
		}
	}
}
void init(int N, int M, vector<int> U, vector<int> V, vector<int> W){
	for(int i=0;i<M;i++){
		e[U[i]].push_back(V[i]);
		e[V[i]].push_back(U[i]);
		dsu.merge(U[i],V[i]);
		dsu.mx[dsu.find(V[i])]=max(dsu.mx[dsu.find(V[i])],W[i]);
	}
	for(int i=0;i<N;i++){
		if(used[i]==0){
			h=0;
			dfs(i);
			if(h==1){
				ans[dsu.find(i)]=-1;
			}
			else{
				ans[dsu.find(i)]=1;
			}
		}
	}
}

int getMinimumFuelCapacity(int X, int Y) {
	if(dsu.find(X)!=dsu.find(Y) || ans[dsu.find(X)]==-1){
		return -1;
	}
	else{
		return dsu.mx[dsu.find(X)];	
	}
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 3 ms 3412 KB Output is correct
3 Correct 2 ms 3412 KB Output is correct
4 Correct 2 ms 3412 KB Output is correct
5 Correct 2 ms 3412 KB Output is correct
6 Incorrect 2 ms 3412 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 3 ms 3412 KB Output is correct
3 Incorrect 98 ms 11832 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 3 ms 3412 KB Output is correct
3 Correct 2 ms 3412 KB Output is correct
4 Correct 2 ms 3412 KB Output is correct
5 Correct 2 ms 3412 KB Output is correct
6 Incorrect 2 ms 3412 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 3 ms 3412 KB Output is correct
3 Correct 2 ms 3412 KB Output is correct
4 Correct 2 ms 3412 KB Output is correct
5 Correct 2 ms 3412 KB Output is correct
6 Incorrect 2 ms 3412 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 3 ms 3412 KB Output is correct
3 Correct 2 ms 3412 KB Output is correct
4 Correct 2 ms 3412 KB Output is correct
5 Correct 2 ms 3412 KB Output is correct
6 Incorrect 2 ms 3412 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 3 ms 3412 KB Output is correct
3 Correct 2 ms 3412 KB Output is correct
4 Correct 2 ms 3412 KB Output is correct
5 Correct 2 ms 3412 KB Output is correct
6 Incorrect 2 ms 3412 KB Output isn't correct
7 Halted 0 ms 0 KB -