Submission #420278

# Submission time Handle Problem Language Result Execution time Memory
420278 2021-06-08T08:51:44 Z KalasLavas Race (IOI11_race) C++17
21 / 100
3000 ms 11216 KB
#include <bits/stdc++.h>
#include "race.h"
using namespace std;

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//#undef LOCALKL
#define IO \
ios_base::sync_with_stdio(0);(cin).tie(0);(cout).tie(0)
#define y1 y1_
#define prev prev_
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define eb emplace_back
#define F first
#define S second
#ifdef LOCALKL
// #define cerr cerr<<"\33[1;32m"
// #define cout cout<<"\33[0m"
#else
#ifndef OO
#define endl '\n'
#define cerr if(1){}else cerr
#endif
#endif
#define OK cerr<<"OK\n"<<endl;
#define setpre(k) fixed<<setprecision(k)
#define mmset(k,y) memset(k,y,sizeof(k))
#define sz(x) ((int)(x).size())
using pii = pair<int,int>;
using pll = pair<long long,long long>;
using ull = unsigned long long;
using intt = long long;
using ll = long long;
using ld = long double;

const ll m9 = 998244353;
const ll m7 = 1000000007;
const ll m18 = 1000000000000000000;
const ll i127 = 2139062143;
const ll l127 = 9187201950435737471;


int n, k, ans = i127;
bool removed[200002];
vector<pii>g[200002];
map<ll,int>m;

void calc(int v, int parent, int dis, int depth)
{
	if(m[k-dis] or dis==k) ans=min(ans, m[k-dis]+depth);
	for(pii u : g[v])
		if(u.F!=parent and !removed[u.F])
			calc(u.F, v, dis+u.S, depth+1);
}

void add_dis(int v, int parent, int dis, int depth)
{
	m[dis] = depth;
	for(pii u : g[v])
		if(u.F!=parent and !removed[u.F])
			add_dis(u.F, v, dis+u.S, depth+1);
}

int best_path(int N, int K, int H[][2], int L[])
{
	n=N; k=K;
	for(int i=0;i<n-1;i++)
	{
		g[H[i][0]].emplace_back(H[i][1], L[i]);
		g[H[i][1]].emplace_back(H[i][0], L[i]);
	}
	for(int i=0;i<n;i++)
	{
		m.clear();
		for(pii u : g[i])
			if(!removed[u.F])
			{
				calc(u.F, i, u.S, 1);
				add_dis(u.F, i, u.S, 1);
			}
		// cerr<<i<<' '<<ans<<endl;
	}

	return ans==i127?-1:ans;
}

# Verdict Execution time Memory Grader output
1 Correct 5 ms 4940 KB Output is correct
2 Correct 5 ms 4940 KB Output is correct
3 Correct 5 ms 4940 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 5 ms 5004 KB Output is correct
6 Correct 4 ms 5012 KB Output is correct
7 Correct 5 ms 5012 KB Output is correct
8 Correct 5 ms 5068 KB Output is correct
9 Correct 5 ms 4940 KB Output is correct
10 Correct 5 ms 5012 KB Output is correct
11 Correct 5 ms 4940 KB Output is correct
12 Correct 5 ms 4948 KB Output is correct
13 Correct 5 ms 5012 KB Output is correct
14 Correct 5 ms 4940 KB Output is correct
15 Correct 5 ms 4940 KB Output is correct
16 Correct 5 ms 4940 KB Output is correct
17 Correct 5 ms 4940 KB Output is correct
18 Correct 5 ms 5016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4940 KB Output is correct
2 Correct 5 ms 4940 KB Output is correct
3 Correct 5 ms 4940 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 5 ms 5004 KB Output is correct
6 Correct 4 ms 5012 KB Output is correct
7 Correct 5 ms 5012 KB Output is correct
8 Correct 5 ms 5068 KB Output is correct
9 Correct 5 ms 4940 KB Output is correct
10 Correct 5 ms 5012 KB Output is correct
11 Correct 5 ms 4940 KB Output is correct
12 Correct 5 ms 4948 KB Output is correct
13 Correct 5 ms 5012 KB Output is correct
14 Correct 5 ms 4940 KB Output is correct
15 Correct 5 ms 4940 KB Output is correct
16 Correct 5 ms 4940 KB Output is correct
17 Correct 5 ms 4940 KB Output is correct
18 Correct 5 ms 5016 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 4 ms 4940 KB Output is correct
21 Correct 201 ms 5096 KB Output is correct
22 Correct 333 ms 5196 KB Output is correct
23 Correct 334 ms 5176 KB Output is correct
24 Correct 339 ms 5196 KB Output is correct
25 Correct 358 ms 5196 KB Output is correct
26 Correct 345 ms 5196 KB Output is correct
27 Correct 62 ms 5072 KB Output is correct
28 Correct 340 ms 5196 KB Output is correct
29 Correct 348 ms 5316 KB Output is correct
30 Correct 343 ms 5180 KB Output is correct
31 Correct 359 ms 5196 KB Output is correct
32 Correct 357 ms 5196 KB Output is correct
33 Correct 351 ms 5196 KB Output is correct
34 Correct 237 ms 5196 KB Output is correct
35 Correct 209 ms 5316 KB Output is correct
36 Correct 182 ms 5196 KB Output is correct
37 Correct 193 ms 5196 KB Output is correct
38 Correct 265 ms 5196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4940 KB Output is correct
2 Correct 5 ms 4940 KB Output is correct
3 Correct 5 ms 4940 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 5 ms 5004 KB Output is correct
6 Correct 4 ms 5012 KB Output is correct
7 Correct 5 ms 5012 KB Output is correct
8 Correct 5 ms 5068 KB Output is correct
9 Correct 5 ms 4940 KB Output is correct
10 Correct 5 ms 5012 KB Output is correct
11 Correct 5 ms 4940 KB Output is correct
12 Correct 5 ms 4948 KB Output is correct
13 Correct 5 ms 5012 KB Output is correct
14 Correct 5 ms 4940 KB Output is correct
15 Correct 5 ms 4940 KB Output is correct
16 Correct 5 ms 4940 KB Output is correct
17 Correct 5 ms 4940 KB Output is correct
18 Correct 5 ms 5016 KB Output is correct
19 Execution timed out 3091 ms 11216 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4940 KB Output is correct
2 Correct 5 ms 4940 KB Output is correct
3 Correct 5 ms 4940 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 5 ms 5004 KB Output is correct
6 Correct 4 ms 5012 KB Output is correct
7 Correct 5 ms 5012 KB Output is correct
8 Correct 5 ms 5068 KB Output is correct
9 Correct 5 ms 4940 KB Output is correct
10 Correct 5 ms 5012 KB Output is correct
11 Correct 5 ms 4940 KB Output is correct
12 Correct 5 ms 4948 KB Output is correct
13 Correct 5 ms 5012 KB Output is correct
14 Correct 5 ms 4940 KB Output is correct
15 Correct 5 ms 4940 KB Output is correct
16 Correct 5 ms 4940 KB Output is correct
17 Correct 5 ms 4940 KB Output is correct
18 Correct 5 ms 5016 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 4 ms 4940 KB Output is correct
21 Correct 201 ms 5096 KB Output is correct
22 Correct 333 ms 5196 KB Output is correct
23 Correct 334 ms 5176 KB Output is correct
24 Correct 339 ms 5196 KB Output is correct
25 Correct 358 ms 5196 KB Output is correct
26 Correct 345 ms 5196 KB Output is correct
27 Correct 62 ms 5072 KB Output is correct
28 Correct 340 ms 5196 KB Output is correct
29 Correct 348 ms 5316 KB Output is correct
30 Correct 343 ms 5180 KB Output is correct
31 Correct 359 ms 5196 KB Output is correct
32 Correct 357 ms 5196 KB Output is correct
33 Correct 351 ms 5196 KB Output is correct
34 Correct 237 ms 5196 KB Output is correct
35 Correct 209 ms 5316 KB Output is correct
36 Correct 182 ms 5196 KB Output is correct
37 Correct 193 ms 5196 KB Output is correct
38 Correct 265 ms 5196 KB Output is correct
39 Execution timed out 3091 ms 11216 KB Time limit exceeded
40 Halted 0 ms 0 KB -