Submission #70774

# Submission time Handle Problem Language Result Execution time Memory
70774 2018-08-23T10:42:41 Z MrTEK Race (IOI11_race) C++14
21 / 100
3000 ms 14196 KB
#include "race.h"
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define len(a) (int)a.size()
#define fi first
#define sc second
#define d1(w) cerr<<#w<<":"<<w<<endl;
#define d2(w,c) cerr<<#w<<":"<<w<<" "<<#c<<":"<<c<<endl;
#define d3(w,c,z) cerr<<#w<<":"<<w<<" "<<#c<<":"<<c<<" "<<#z<<":"<<z<<endl;
#define left isc+isc
#define right isc+isc+1
#define mid (l+r)/2
#define FAfi_IO ios_base::sync_with_fidio(false);
#define escl '\n'
#define bit __builtin_popcount

typedef long long int ll;

const int maxn = 620;
const long long LINF = 1e18;
const int LOG = 31;
const int INF = 1e9;
const int N = 2e5 + 5;
const int M = 1e6 + 5;
const int SQ = 350;
const int MOD = 998244353;

typedef long long int lli;
typedef pair<int,int> pii;

vector <pii> ed[N],vec;
vector <int> v;
int n,k,ans = INF,sub[N],vis[N],mark[M];

int calc(int cur,int back = -1) {
	sub[cur] = 0;
	for (auto i : ed[cur])
		if (i.fi != back && vis[i.fi] == 0)
			sub[cur] += calc(i.fi,cur);
	return ++sub[cur];
}

int find(int cur,int back,int sz) {
	for (auto i : ed[cur])
		if (i.fi != back && vis[i.fi] == 0 && sub[i.fi] > sz / 2)
			return find(i.fi,cur,sz);
	return cur;
}

void dfs(int cur,int back,int sum,int step) {
	if (sum == k)
		ans = min(ans,step);
	if (sum < k) {
		ans = min(ans,mark[k - sum] + step);
		vec.pb(mp(sum,step));
	}
	for (auto i : ed[cur]) {
		if (vis[i.fi] == 0 && i.fi != back)
			dfs(i.fi,cur,sum + i.sc,step + 1);
	}
}


void solve(int cur = 1) {
	int cen = find(cur,-1,calc(cur));
	for (auto i : ed[cen]) {
		if (vis[i.fi]) continue;
		vec.clear();
		dfs(i.fi,cen,i.sc,1);
		for (auto j : vec) {
			mark[j.fi] = min(mark[j.fi],j.sc);
			v.pb(j.fi);
		}
	}
	for (auto i : v)
		mark[i] = INF;
	vis[cen] = 1;
	for (auto i : ed[cen])
		if (vis[i.fi] == 0)
			solve(i.fi);
}


int best_path(int N, int K, int H[][2], int L[]) {
	n = N;
	k = K;
	for (int i = 0 ; i < n - 1 ; i++) {
		int u = H[i][0] + 1, v = H[i][1] + 1 , c = L[i];
		ed[u].pb(mp(v,c));
		ed[v].pb(mp(u,c));
	}
	for (int i = 0 ; i <= k ; i++) mark[i] = INF;	
	solve();
	if (ans >= INF) return -1;
	return ans;
}

# Verdict Execution time Memory Grader output
1 Correct 8 ms 5112 KB Output is correct
2 Correct 9 ms 5156 KB Output is correct
3 Correct 9 ms 5156 KB Output is correct
4 Correct 7 ms 5212 KB Output is correct
5 Correct 7 ms 5216 KB Output is correct
6 Correct 8 ms 5224 KB Output is correct
7 Correct 7 ms 5312 KB Output is correct
8 Correct 9 ms 5372 KB Output is correct
9 Correct 10 ms 5372 KB Output is correct
10 Correct 7 ms 5372 KB Output is correct
11 Correct 8 ms 5372 KB Output is correct
12 Correct 7 ms 5372 KB Output is correct
13 Correct 7 ms 5496 KB Output is correct
14 Correct 10 ms 5496 KB Output is correct
15 Correct 8 ms 5504 KB Output is correct
16 Correct 8 ms 5504 KB Output is correct
17 Correct 8 ms 5516 KB Output is correct
18 Correct 8 ms 5532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 5112 KB Output is correct
2 Correct 9 ms 5156 KB Output is correct
3 Correct 9 ms 5156 KB Output is correct
4 Correct 7 ms 5212 KB Output is correct
5 Correct 7 ms 5216 KB Output is correct
6 Correct 8 ms 5224 KB Output is correct
7 Correct 7 ms 5312 KB Output is correct
8 Correct 9 ms 5372 KB Output is correct
9 Correct 10 ms 5372 KB Output is correct
10 Correct 7 ms 5372 KB Output is correct
11 Correct 8 ms 5372 KB Output is correct
12 Correct 7 ms 5372 KB Output is correct
13 Correct 7 ms 5496 KB Output is correct
14 Correct 10 ms 5496 KB Output is correct
15 Correct 8 ms 5504 KB Output is correct
16 Correct 8 ms 5504 KB Output is correct
17 Correct 8 ms 5516 KB Output is correct
18 Correct 8 ms 5532 KB Output is correct
19 Correct 9 ms 5532 KB Output is correct
20 Correct 9 ms 5540 KB Output is correct
21 Correct 12 ms 5656 KB Output is correct
22 Correct 14 ms 9140 KB Output is correct
23 Correct 15 ms 9140 KB Output is correct
24 Correct 14 ms 9140 KB Output is correct
25 Correct 24 ms 9140 KB Output is correct
26 Correct 12 ms 9140 KB Output is correct
27 Correct 15 ms 9140 KB Output is correct
28 Correct 19 ms 9140 KB Output is correct
29 Correct 19 ms 9140 KB Output is correct
30 Correct 23 ms 9140 KB Output is correct
31 Correct 23 ms 9140 KB Output is correct
32 Correct 23 ms 9140 KB Output is correct
33 Correct 28 ms 9140 KB Output is correct
34 Correct 17 ms 9140 KB Output is correct
35 Correct 21 ms 9140 KB Output is correct
36 Correct 18 ms 9552 KB Output is correct
37 Correct 22 ms 9552 KB Output is correct
38 Correct 24 ms 9552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 5112 KB Output is correct
2 Correct 9 ms 5156 KB Output is correct
3 Correct 9 ms 5156 KB Output is correct
4 Correct 7 ms 5212 KB Output is correct
5 Correct 7 ms 5216 KB Output is correct
6 Correct 8 ms 5224 KB Output is correct
7 Correct 7 ms 5312 KB Output is correct
8 Correct 9 ms 5372 KB Output is correct
9 Correct 10 ms 5372 KB Output is correct
10 Correct 7 ms 5372 KB Output is correct
11 Correct 8 ms 5372 KB Output is correct
12 Correct 7 ms 5372 KB Output is correct
13 Correct 7 ms 5496 KB Output is correct
14 Correct 10 ms 5496 KB Output is correct
15 Correct 8 ms 5504 KB Output is correct
16 Correct 8 ms 5504 KB Output is correct
17 Correct 8 ms 5516 KB Output is correct
18 Correct 8 ms 5532 KB Output is correct
19 Execution timed out 3038 ms 14196 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 5112 KB Output is correct
2 Correct 9 ms 5156 KB Output is correct
3 Correct 9 ms 5156 KB Output is correct
4 Correct 7 ms 5212 KB Output is correct
5 Correct 7 ms 5216 KB Output is correct
6 Correct 8 ms 5224 KB Output is correct
7 Correct 7 ms 5312 KB Output is correct
8 Correct 9 ms 5372 KB Output is correct
9 Correct 10 ms 5372 KB Output is correct
10 Correct 7 ms 5372 KB Output is correct
11 Correct 8 ms 5372 KB Output is correct
12 Correct 7 ms 5372 KB Output is correct
13 Correct 7 ms 5496 KB Output is correct
14 Correct 10 ms 5496 KB Output is correct
15 Correct 8 ms 5504 KB Output is correct
16 Correct 8 ms 5504 KB Output is correct
17 Correct 8 ms 5516 KB Output is correct
18 Correct 8 ms 5532 KB Output is correct
19 Correct 9 ms 5532 KB Output is correct
20 Correct 9 ms 5540 KB Output is correct
21 Correct 12 ms 5656 KB Output is correct
22 Correct 14 ms 9140 KB Output is correct
23 Correct 15 ms 9140 KB Output is correct
24 Correct 14 ms 9140 KB Output is correct
25 Correct 24 ms 9140 KB Output is correct
26 Correct 12 ms 9140 KB Output is correct
27 Correct 15 ms 9140 KB Output is correct
28 Correct 19 ms 9140 KB Output is correct
29 Correct 19 ms 9140 KB Output is correct
30 Correct 23 ms 9140 KB Output is correct
31 Correct 23 ms 9140 KB Output is correct
32 Correct 23 ms 9140 KB Output is correct
33 Correct 28 ms 9140 KB Output is correct
34 Correct 17 ms 9140 KB Output is correct
35 Correct 21 ms 9140 KB Output is correct
36 Correct 18 ms 9552 KB Output is correct
37 Correct 22 ms 9552 KB Output is correct
38 Correct 24 ms 9552 KB Output is correct
39 Execution timed out 3038 ms 14196 KB Time limit exceeded
40 Halted 0 ms 0 KB -