Submission #97861

# Submission time Handle Problem Language Result Execution time Memory
97861 2019-02-19T03:38:42 Z TuGSGeReL Race (IOI11_race) C++17
21 / 100
3000 ms 40604 KB
    #include "race.h"
    #include<bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    using namespace std;
    using namespace __gnu_pbds;
    #define ll long long
    #define mp make_pair
    #define pub push_back
    #define pob pop_back()
    #define ss second
    #define ff first
    #define mt make_tuple
    #define pof pop_front()
    #define fbo find_by_order
    #define ook order_of_key
    typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
    int i,ans=1e9,c[200001],used[200001];
    vector<pair<int,int> >v[200001];
    unordered_map<int,int>xox,yoy;
    inline void dfs(int u, int par){
    	for(auto x : v[u]) if(x.ff!=par) dfs(x.ff,u); 
    	c[par]+=c[u];
    }
    inline void dfs1(int u, int parr, int s, int d){
    	if(yoy.find(s) == yoy.end())yoy[s]=d;
    	else yoy[s]=min(yoy[s],d);
    	for(auto x : v[u]){
    		if(x.ff!=parr && !used[x.ff]) dfs1(x.ff,u,s+x.ss,d+1);
    	}
    }
    inline int fnd(int u , int sz){
    	for(auto x : v[u]){
    		if(!used[x.ff] && c[x.ff]>sz){
    			c[u]-=c[x.ff];
    			c[x.ff]+=c[u];
    			return fnd(x.ff,sz);
    		}
    	}
    	return u;
    }
    inline void solve(int at, int k){
    	at=fnd(at,c[at]/2);
    	used[at]=1;
    	xox.clear();
    	xox[0]=0;
    	for(auto z : v[at]){
    		if(used[z.ff]) continue;
    		yoy.clear();
    		dfs1(z.ff,at,z.ss,1);
    		for(auto haha : yoy) if(xox.find(k-haha.ff)!=xox.end()) ans=min(ans,haha.ss+xox[k-haha.ff]);
    		for(auto lol : yoy){
    			if(xox.find(lol.ff)==xox.end()) xox[lol.ff]=lol.ss;
    			else xox[lol.ff]=min(xox[lol.ff],lol.ss);
    		}
    	}
    	for(auto hha : v[at]) if(!used[hha.ff]) solve(hha.ff,k);
    }
    int best_path(int N, int K, int H[][2], int L[]) {
    	for(i=0;i<N-1;i++){
    		c[i]=1;
    		v[H[i][0]].pub(mp(H[i][1],L[i]));
    		v[H[i][1]].pub(mp(H[i][0],L[i]));
    	}
    	c[N-1]=1;
    	dfs(0,0);
    	solve(0,K);
    	if(ans==1e9) ans=-1;
    	return ans;
    }
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5120 KB Output is correct
2 Correct 7 ms 5120 KB Output is correct
3 Correct 7 ms 5120 KB Output is correct
4 Correct 7 ms 5120 KB Output is correct
5 Correct 7 ms 5120 KB Output is correct
6 Correct 6 ms 4992 KB Output is correct
7 Correct 7 ms 4992 KB Output is correct
8 Correct 6 ms 5120 KB Output is correct
9 Correct 2 ms 5120 KB Output is correct
10 Correct 7 ms 4992 KB Output is correct
11 Correct 7 ms 4992 KB Output is correct
12 Correct 6 ms 4992 KB Output is correct
13 Correct 7 ms 5120 KB Output is correct
14 Correct 7 ms 4992 KB Output is correct
15 Correct 7 ms 5120 KB Output is correct
16 Correct 6 ms 4992 KB Output is correct
17 Correct 8 ms 5120 KB Output is correct
18 Correct 6 ms 4992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5120 KB Output is correct
2 Correct 7 ms 5120 KB Output is correct
3 Correct 7 ms 5120 KB Output is correct
4 Correct 7 ms 5120 KB Output is correct
5 Correct 7 ms 5120 KB Output is correct
6 Correct 6 ms 4992 KB Output is correct
7 Correct 7 ms 4992 KB Output is correct
8 Correct 6 ms 5120 KB Output is correct
9 Correct 2 ms 5120 KB Output is correct
10 Correct 7 ms 4992 KB Output is correct
11 Correct 7 ms 4992 KB Output is correct
12 Correct 6 ms 4992 KB Output is correct
13 Correct 7 ms 5120 KB Output is correct
14 Correct 7 ms 4992 KB Output is correct
15 Correct 7 ms 5120 KB Output is correct
16 Correct 6 ms 4992 KB Output is correct
17 Correct 8 ms 5120 KB Output is correct
18 Correct 6 ms 4992 KB Output is correct
19 Correct 7 ms 5120 KB Output is correct
20 Correct 7 ms 5120 KB Output is correct
21 Correct 9 ms 5120 KB Output is correct
22 Correct 9 ms 5120 KB Output is correct
23 Correct 9 ms 5120 KB Output is correct
24 Correct 9 ms 5248 KB Output is correct
25 Correct 8 ms 5248 KB Output is correct
26 Correct 9 ms 5120 KB Output is correct
27 Correct 10 ms 5120 KB Output is correct
28 Correct 11 ms 5120 KB Output is correct
29 Correct 10 ms 5248 KB Output is correct
30 Correct 10 ms 4992 KB Output is correct
31 Correct 9 ms 5120 KB Output is correct
32 Correct 9 ms 5248 KB Output is correct
33 Correct 9 ms 5120 KB Output is correct
34 Correct 11 ms 5248 KB Output is correct
35 Correct 8 ms 5120 KB Output is correct
36 Correct 8 ms 5120 KB Output is correct
37 Correct 9 ms 5120 KB Output is correct
38 Correct 10 ms 5248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5120 KB Output is correct
2 Correct 7 ms 5120 KB Output is correct
3 Correct 7 ms 5120 KB Output is correct
4 Correct 7 ms 5120 KB Output is correct
5 Correct 7 ms 5120 KB Output is correct
6 Correct 6 ms 4992 KB Output is correct
7 Correct 7 ms 4992 KB Output is correct
8 Correct 6 ms 5120 KB Output is correct
9 Correct 2 ms 5120 KB Output is correct
10 Correct 7 ms 4992 KB Output is correct
11 Correct 7 ms 4992 KB Output is correct
12 Correct 6 ms 4992 KB Output is correct
13 Correct 7 ms 5120 KB Output is correct
14 Correct 7 ms 4992 KB Output is correct
15 Correct 7 ms 5120 KB Output is correct
16 Correct 6 ms 4992 KB Output is correct
17 Correct 8 ms 5120 KB Output is correct
18 Correct 6 ms 4992 KB Output is correct
19 Correct 361 ms 10820 KB Output is correct
20 Correct 345 ms 10728 KB Output is correct
21 Correct 333 ms 10872 KB Output is correct
22 Correct 329 ms 10872 KB Output is correct
23 Correct 492 ms 11260 KB Output is correct
24 Correct 257 ms 11000 KB Output is correct
25 Correct 778 ms 13112 KB Output is correct
26 Correct 178 ms 14968 KB Output is correct
27 Correct 962 ms 16888 KB Output is correct
28 Execution timed out 3082 ms 40604 KB Time limit exceeded
29 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5120 KB Output is correct
2 Correct 7 ms 5120 KB Output is correct
3 Correct 7 ms 5120 KB Output is correct
4 Correct 7 ms 5120 KB Output is correct
5 Correct 7 ms 5120 KB Output is correct
6 Correct 6 ms 4992 KB Output is correct
7 Correct 7 ms 4992 KB Output is correct
8 Correct 6 ms 5120 KB Output is correct
9 Correct 2 ms 5120 KB Output is correct
10 Correct 7 ms 4992 KB Output is correct
11 Correct 7 ms 4992 KB Output is correct
12 Correct 6 ms 4992 KB Output is correct
13 Correct 7 ms 5120 KB Output is correct
14 Correct 7 ms 4992 KB Output is correct
15 Correct 7 ms 5120 KB Output is correct
16 Correct 6 ms 4992 KB Output is correct
17 Correct 8 ms 5120 KB Output is correct
18 Correct 6 ms 4992 KB Output is correct
19 Correct 7 ms 5120 KB Output is correct
20 Correct 7 ms 5120 KB Output is correct
21 Correct 9 ms 5120 KB Output is correct
22 Correct 9 ms 5120 KB Output is correct
23 Correct 9 ms 5120 KB Output is correct
24 Correct 9 ms 5248 KB Output is correct
25 Correct 8 ms 5248 KB Output is correct
26 Correct 9 ms 5120 KB Output is correct
27 Correct 10 ms 5120 KB Output is correct
28 Correct 11 ms 5120 KB Output is correct
29 Correct 10 ms 5248 KB Output is correct
30 Correct 10 ms 4992 KB Output is correct
31 Correct 9 ms 5120 KB Output is correct
32 Correct 9 ms 5248 KB Output is correct
33 Correct 9 ms 5120 KB Output is correct
34 Correct 11 ms 5248 KB Output is correct
35 Correct 8 ms 5120 KB Output is correct
36 Correct 8 ms 5120 KB Output is correct
37 Correct 9 ms 5120 KB Output is correct
38 Correct 10 ms 5248 KB Output is correct
39 Correct 361 ms 10820 KB Output is correct
40 Correct 345 ms 10728 KB Output is correct
41 Correct 333 ms 10872 KB Output is correct
42 Correct 329 ms 10872 KB Output is correct
43 Correct 492 ms 11260 KB Output is correct
44 Correct 257 ms 11000 KB Output is correct
45 Correct 778 ms 13112 KB Output is correct
46 Correct 178 ms 14968 KB Output is correct
47 Correct 962 ms 16888 KB Output is correct
48 Execution timed out 3082 ms 40604 KB Time limit exceeded
49 Halted 0 ms 0 KB -