Submission #679177

# Submission time Handle Problem Language Result Execution time Memory
679177 2023-01-07T16:18:30 Z Dan4Life Swapping Cities (APIO20_swap) C++17
0 / 100
2000 ms 50124 KB
#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define SZ(a) (int)a.size()
using ll = long long;

const int maxn = (int)3e5+10;
const int lgn = 20;
const int INF = (int)1e9;

vector<int> adj[maxn];
int n, m, num, tim;
int jmp[lgn][maxn];
int p[maxn], lev[maxn], wei[maxn], line[maxn], good[maxn];

struct Edge{ int u, v, w, i; };
Edge edge[maxn];

int getPath(int x, int steps){
	for(int i = lgn-1; i >= 0; i--)
		if(steps&(1<<i) and x!=-1) x = jmp[i][x];
	return x; 
}

int lca(int a, int b){
	if(a==b) return a;
	if(jmp[0][a]==jmp[0][b]) return jmp[0][a];
	if(lev[a] < lev[b]) swap(a,b);
	a = getPath(a, lev[a]-lev[b]);
	for(int i = lgn-1; i >= 0; i--)
		if(jmp[i][a]!=-1 and jmp[i][a]!=jmp[i][b])
			a = jmp[i][a], b = jmp[i][b];
	return lca(a,b);
}

int findSet(int i){ return p[i]==i?i:p[i]=findSet(p[i]); }
bool isSameSet(int i, int j) { return findSet(i)==findSet(j); }

void unionSet(Edge &e){
	int i = e.u, j = e.v; wei[e.i] = e.w;
	int x = findSet(i), y = findSet(j);
	p[x]=p[y]=p[num]=num;
	if(x!=y) adj[num].pb(y);
	adj[num].pb(x); line[num]-=(x==y);
	good[num] |= good[i] | good[j] | !line[num] | !(line[x] and line[y]);
	num++;
}

void dfs(int s, int p){
	if(p!=-1) lev[s] = lev[p]+1, jmp[0][s] = p;
	for(auto u : adj[s]) if(u!=p) dfs(u,s);
}

void init(int N, int M, vector<int> u, vector<int> v, vector<int> w) {
	n = N, m = M; num = n; memset(jmp,-1,sizeof(jmp));
	for(int i = 0; i < n+m; i++) p[i] = i, line[i] = 1;
	for(int i = 0; i < m; i++) edge[i] = {u[i],v[i],w[i],i};
	sort(edge,edge+M,[&](Edge x, Edge y){ return x.w<y.w; });
	for(int i = 0; i < m; i++) edge[i].i=i, unionSet(edge[i]);
	dfs(num-1,-1);
	for(int i = 1; i < lgn; i++)
		for(int j = 0; j+(1<<i)-1 < n; j++)
			if(jmp[i-1][j]!=-1) jmp[i][j] = jmp[i-1][jmp[i-1][j]];
}

int getMinimumFuelCapacity(int x, int y) {
	int z = lca(x,y);
	while(jmp[0][z]!=-1 and !good[z])
		for(int i = lgn-1; i >= 0; i--) 
			if(jmp[i][z]!=-1 and !good[i]) z = jmp[i][z];
	return good[z]?wei[z-n]:-1;
}
# Verdict Execution time Memory Grader output
1 Correct 14 ms 30804 KB Output is correct
2 Correct 13 ms 30804 KB Output is correct
3 Correct 14 ms 30804 KB Output is correct
4 Correct 12 ms 30908 KB Output is correct
5 Correct 14 ms 30928 KB Output is correct
6 Correct 13 ms 30856 KB Output is correct
7 Correct 13 ms 30904 KB Output is correct
8 Correct 16 ms 30932 KB Output is correct
9 Correct 62 ms 40380 KB Output is correct
10 Correct 73 ms 42604 KB Output is correct
11 Correct 81 ms 42460 KB Output is correct
12 Correct 76 ms 43176 KB Output is correct
13 Correct 77 ms 45484 KB Output is correct
14 Correct 94 ms 40780 KB Output is correct
15 Correct 659 ms 46876 KB Output is correct
16 Correct 645 ms 46484 KB Output is correct
17 Correct 499 ms 47116 KB Output is correct
18 Execution timed out 2075 ms 49332 KB Time limit exceeded
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 30804 KB Output is correct
2 Correct 13 ms 30804 KB Output is correct
3 Execution timed out 2074 ms 50124 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 30804 KB Output is correct
2 Correct 13 ms 30804 KB Output is correct
3 Correct 14 ms 30804 KB Output is correct
4 Correct 12 ms 30908 KB Output is correct
5 Correct 14 ms 30928 KB Output is correct
6 Correct 13 ms 30856 KB Output is correct
7 Correct 13 ms 30904 KB Output is correct
8 Correct 16 ms 30932 KB Output is correct
9 Correct 15 ms 30804 KB Output is correct
10 Incorrect 13 ms 30916 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 30804 KB Output is correct
2 Correct 14 ms 30804 KB Output is correct
3 Correct 13 ms 30804 KB Output is correct
4 Correct 14 ms 30804 KB Output is correct
5 Correct 12 ms 30908 KB Output is correct
6 Correct 14 ms 30928 KB Output is correct
7 Correct 13 ms 30856 KB Output is correct
8 Correct 13 ms 30904 KB Output is correct
9 Correct 16 ms 30932 KB Output is correct
10 Correct 62 ms 40380 KB Output is correct
11 Correct 73 ms 42604 KB Output is correct
12 Correct 81 ms 42460 KB Output is correct
13 Correct 76 ms 43176 KB Output is correct
14 Correct 77 ms 45484 KB Output is correct
15 Incorrect 13 ms 30916 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 30804 KB Output is correct
2 Correct 13 ms 30804 KB Output is correct
3 Correct 14 ms 30804 KB Output is correct
4 Correct 12 ms 30908 KB Output is correct
5 Correct 14 ms 30928 KB Output is correct
6 Correct 13 ms 30856 KB Output is correct
7 Correct 13 ms 30904 KB Output is correct
8 Correct 16 ms 30932 KB Output is correct
9 Correct 62 ms 40380 KB Output is correct
10 Correct 73 ms 42604 KB Output is correct
11 Correct 81 ms 42460 KB Output is correct
12 Correct 76 ms 43176 KB Output is correct
13 Correct 77 ms 45484 KB Output is correct
14 Correct 94 ms 40780 KB Output is correct
15 Correct 659 ms 46876 KB Output is correct
16 Correct 645 ms 46484 KB Output is correct
17 Correct 499 ms 47116 KB Output is correct
18 Execution timed out 2075 ms 49332 KB Time limit exceeded
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 30804 KB Output is correct
2 Correct 14 ms 30804 KB Output is correct
3 Correct 13 ms 30804 KB Output is correct
4 Correct 14 ms 30804 KB Output is correct
5 Correct 12 ms 30908 KB Output is correct
6 Correct 14 ms 30928 KB Output is correct
7 Correct 13 ms 30856 KB Output is correct
8 Correct 13 ms 30904 KB Output is correct
9 Correct 16 ms 30932 KB Output is correct
10 Correct 62 ms 40380 KB Output is correct
11 Correct 73 ms 42604 KB Output is correct
12 Correct 81 ms 42460 KB Output is correct
13 Correct 76 ms 43176 KB Output is correct
14 Correct 77 ms 45484 KB Output is correct
15 Correct 94 ms 40780 KB Output is correct
16 Correct 659 ms 46876 KB Output is correct
17 Correct 645 ms 46484 KB Output is correct
18 Correct 499 ms 47116 KB Output is correct
19 Execution timed out 2075 ms 49332 KB Time limit exceeded
20 Halted 0 ms 0 KB -