Submission #150082

# Submission time Handle Problem Language Result Execution time Memory
150082 2019-09-01T07:41:31 Z 욱방켜!! (twitch.tv/wookje)(#3584, kig9981, cheetose, jh05013) Trip to the Galapagos Islands (FXCUP4_island) C++17
0 / 100
273 ms 29024 KB
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int,int,int,int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const ll MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) {ll ret=1; for(;b;b>>=1,a=(a*a)%MMM)if(b&1)ret=(ret*a)% MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };

int parent[100000];
int find(int a)
{
	if (parent[a] < 0)return a;
	return parent[a] = find(parent[a]);
}
void merge(int a, int b)
{
	a = find(a), b = find(b);
	if (a != b)
	{
		parent[b] = a;
	}
}
bool sub1;
int f[100000],a[100000],s[300000],e[300000];
VPi v[100000];
int p[100000][17],mn[100000][17],depth[100000];

void dfs(int N,int pp,int d)
{
	depth[N]=d;
	p[N][0]=pp;
	for(auto next:v[N])
	{
		if(next.X==pp)continue;
		mn[next.X][0]=next.Y;
		dfs(next.X,N,d+1);
	}
}
int LCA(int x, int y)
{
	if (depth[x] < depth[y])swap(x, y);
	int dif = depth[x] - depth[y];
	for (int j = 0; dif > 0; j++)
	{
		if (dif & 1)x = p[x][j];
		dif /= 2;
	}

	if (x != y)
	{
		fdn(j,16,0,1)
		{
			if (p[x][j] != -1 && p[x][j] != p[y][j])
			{
				x = p[x][j];
				y = p[y][j];
			}
		}
		x = p[x][0];
	}
	return x;
}
int query(int U,int V)
{
	int ans=INF;
	int t=depth[V]-depth[U];
	fdn(i,16,0,1)
	{
		if(t&(1<<i))
		{
			ans=min(ans,mn[V][i]);
			V=p[V][i];
		}
	}
	return ans;
}
void Init(int K, Vi F, Vi S, Vi E)
{
	MEM_1(parent);
	fill(&mn[0][0],&mn[99999][17],INF);
	int N=F.size(),M=S.size();
	if(K==N)sub1=1;
	fup(i,0,N-1,1)
	{
		f[i]=F[i];
		a[f[i]]=i;
	}
	fdn(i,M-1,0,1)
	{
		s[i]=S[i],e[i]=E[i];
		s[i]=a[s[i]],e[i]=a[e[i]];
		if(find(s[i])!=find(e[i]))
		{
			merge(s[i],e[i]);
			v[s[i]].pb(mp(e[i],i));
			v[e[i]].pb(mp(s[i],i));
		}
	}
	dfs(0,-1,0);
	fup(j,0,15,1)
		fup(i,0,N-1,1)
	{
		if(p[i][j]!=-1)
		{
			p[i][j+1]=p[p[i][j]][j];
			mn[i][j+1]=min(mn[i][j],mn[p[i][j]][j]);
		}
	}
}

int Separate(int A, int B)
{
	int U=LCA(A,B);
	return min(query(U,A),query(U,B))+1;
}
# Verdict Execution time Memory Grader output
1 Incorrect 273 ms 29024 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 9856 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 9856 KB Output isn't correct
2 Halted 0 ms 0 KB -