# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
304708 | 2020-09-21T17:51:58 Z | JovanK26 | Mousetrap (CEOI17_mousetrap) | C++14 | 1045 ms | 158584 KB |
#include <bits/stdc++.h> using namespace std; vector<int> tree[1000001]; int prt[1000001]; int f[1000001]; vector< pair<int,int> > subtrees; int ispath[1000001]; int n,m,t; int dfs1(int cur,int prev) { int par=-1; for(int i=0;i<tree[cur].size();i++) { if(tree[cur][i]==prev)par=i; } if(par!=-1) { tree[cur].erase(tree[cur].begin()+par); } prt[cur]=prev; int rez=-1; if(cur==m)rez=0; for(int i=0;i<tree[cur].size();i++) { rez=max(rez,dfs1(tree[cur][i],cur)); } ispath[cur]=rez; if(rez==-1)return rez; return rez+1; } void dfs2(int cur,int w) { if(tree[cur].size()==0) { f[cur]=w; return; } if(ispath[cur]==-1) { int neww=w+tree[cur].size(); for(int i=0;i<tree[cur].size();i++) { dfs2(tree[cur][i],neww); } if(tree[cur].size()==1) { f[cur]=w+1; return; } int best=-1; int sbest=-1; for(int i=0;i<tree[cur].size();i++) { if(f[tree[cur][i]]>best) { sbest=best; best=f[tree[cur][i]]; continue; } if(f[tree[cur][i]]>sbest) { sbest=f[tree[cur][i]]; } } f[cur]=sbest; return; } int neww=w+tree[cur].size()-1; if(cur==t)neww=0; if(cur==m)neww++; for(int i=0;i<tree[cur].size();i++) { dfs2(tree[cur][i],neww); } if(cur==t)return; for(int i=0;i<tree[cur].size();i++) { if(ispath[tree[cur][i]]==-1) { subtrees.push_back(make_pair(ispath[cur],f[tree[cur][i]])); } } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> t >> m; m--; t--; int a,b; for(int i=0;i<n-1;i++) { cin >> a >> b; a--; b--; tree[a].push_back(b); tree[b].push_back(a); } int pathl=dfs1(t,-1); dfs2(t,0); sort(subtrees.begin(),subtrees.end()); int l=0; int r=n; int med; while(l<r) { med=(l+r)/2; int x=0; int y=0; int pt=0; for(int i=0;i<pathl;i++) { if(pt>=subtrees.size()) { r=med; break; } x++; int ydelta=0; while(pt<subtrees.size() && subtrees[pt].first<=i) { if(subtrees[pt].second+y>med) { ydelta++; x--; } pt++; } y+=ydelta; if(x<0 || y>med) { l=med+1; break; } } } cout << l<<'\n'; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 23808 KB | Output is correct |
2 | Correct | 15 ms | 23808 KB | Output is correct |
3 | Correct | 15 ms | 23808 KB | Output is correct |
4 | Correct | 15 ms | 23808 KB | Output is correct |
5 | Correct | 15 ms | 23808 KB | Output is correct |
6 | Correct | 15 ms | 23808 KB | Output is correct |
7 | Correct | 15 ms | 23808 KB | Output is correct |
8 | Correct | 15 ms | 23808 KB | Output is correct |
9 | Correct | 14 ms | 23808 KB | Output is correct |
10 | Correct | 15 ms | 23808 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 357 ms | 66808 KB | Output is correct |
2 | Correct | 324 ms | 71416 KB | Output is correct |
3 | Correct | 1006 ms | 76920 KB | Output is correct |
4 | Correct | 488 ms | 52472 KB | Output is correct |
5 | Correct | 1045 ms | 76832 KB | Output is correct |
6 | Correct | 1036 ms | 76792 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 23808 KB | Output is correct |
2 | Correct | 15 ms | 23808 KB | Output is correct |
3 | Correct | 15 ms | 23808 KB | Output is correct |
4 | Correct | 15 ms | 23808 KB | Output is correct |
5 | Correct | 15 ms | 23808 KB | Output is correct |
6 | Correct | 15 ms | 23808 KB | Output is correct |
7 | Correct | 15 ms | 23808 KB | Output is correct |
8 | Correct | 15 ms | 23808 KB | Output is correct |
9 | Correct | 14 ms | 23808 KB | Output is correct |
10 | Correct | 15 ms | 23808 KB | Output is correct |
11 | Correct | 15 ms | 23808 KB | Output is correct |
12 | Correct | 15 ms | 23936 KB | Output is correct |
13 | Correct | 16 ms | 23936 KB | Output is correct |
14 | Correct | 15 ms | 23936 KB | Output is correct |
15 | Correct | 16 ms | 23936 KB | Output is correct |
16 | Correct | 15 ms | 23936 KB | Output is correct |
17 | Correct | 15 ms | 23936 KB | Output is correct |
18 | Correct | 16 ms | 23936 KB | Output is correct |
19 | Correct | 15 ms | 23928 KB | Output is correct |
20 | Correct | 16 ms | 23936 KB | Output is correct |
21 | Correct | 15 ms | 23936 KB | Output is correct |
22 | Correct | 15 ms | 23936 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 23808 KB | Output is correct |
2 | Correct | 15 ms | 23808 KB | Output is correct |
3 | Correct | 15 ms | 23808 KB | Output is correct |
4 | Correct | 15 ms | 23808 KB | Output is correct |
5 | Correct | 15 ms | 23808 KB | Output is correct |
6 | Correct | 15 ms | 23808 KB | Output is correct |
7 | Correct | 15 ms | 23808 KB | Output is correct |
8 | Correct | 15 ms | 23808 KB | Output is correct |
9 | Correct | 14 ms | 23808 KB | Output is correct |
10 | Correct | 15 ms | 23808 KB | Output is correct |
11 | Correct | 357 ms | 66808 KB | Output is correct |
12 | Correct | 324 ms | 71416 KB | Output is correct |
13 | Correct | 1006 ms | 76920 KB | Output is correct |
14 | Correct | 488 ms | 52472 KB | Output is correct |
15 | Correct | 1045 ms | 76832 KB | Output is correct |
16 | Correct | 1036 ms | 76792 KB | Output is correct |
17 | Correct | 15 ms | 23808 KB | Output is correct |
18 | Correct | 15 ms | 23936 KB | Output is correct |
19 | Correct | 16 ms | 23936 KB | Output is correct |
20 | Correct | 15 ms | 23936 KB | Output is correct |
21 | Correct | 16 ms | 23936 KB | Output is correct |
22 | Correct | 15 ms | 23936 KB | Output is correct |
23 | Correct | 15 ms | 23936 KB | Output is correct |
24 | Correct | 16 ms | 23936 KB | Output is correct |
25 | Correct | 15 ms | 23928 KB | Output is correct |
26 | Correct | 16 ms | 23936 KB | Output is correct |
27 | Correct | 15 ms | 23936 KB | Output is correct |
28 | Correct | 15 ms | 23936 KB | Output is correct |
29 | Correct | 18 ms | 23808 KB | Output is correct |
30 | Correct | 370 ms | 80228 KB | Output is correct |
31 | Correct | 365 ms | 80248 KB | Output is correct |
32 | Correct | 435 ms | 154872 KB | Output is correct |
33 | Correct | 431 ms | 158584 KB | Output is correct |
34 | Correct | 1026 ms | 81272 KB | Output is correct |
35 | Correct | 1010 ms | 81528 KB | Output is correct |
36 | Correct | 1028 ms | 90860 KB | Output is correct |
37 | Correct | 1025 ms | 90864 KB | Output is correct |
38 | Correct | 780 ms | 92780 KB | Output is correct |
39 | Correct | 788 ms | 92912 KB | Output is correct |
40 | Correct | 776 ms | 92692 KB | Output is correct |