# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
288743 | 2020-09-01T20:30:23 Z | TadijaSebez | Mousetrap (CEOI17_mousetrap) | C++11 | 1080 ms | 202616 KB |
#include <bits/stdc++.h> using namespace std; #define pb push_back #define pii pair<int,int> const int N=1000050; vector<int> E[N]; int dp[N],dep[N],n,t,m; bool on[N]; void DP(int u,int p){ vector<int> d; for(int v:E[u])if(v!=p){ if(p)dp[v]=dp[u]+E[u].size()-2; DP(v,u); if(on[v])on[u]=1; d.pb(dp[v]); } sort(d.rbegin(),d.rend()); if(d.size()>1)dp[u]=d[1]; dp[u]+=E[u].size()>1; } vector<pii> tmp; void DFS(int u,int p){ if(u==t)return; for(int v:E[u])if(v!=p){ dep[v]=dep[u]+1; if(on[u]&&!on[v])tmp.pb({dep[v],dp[v]+(u==m)}); else DFS(v,u); } } bool Check(int mid){ int need=0; for(auto p:tmp){ if(need>p.first)return 0; if(p.second+need>mid)need++; } return need<=mid; } int main(){ scanf("%i %i %i",&n,&t,&m); for(int i=1,u,v;i<n;i++)scanf("%i %i",&u,&v),E[u].pb(v),E[v].pb(u); on[m]=1;dep[m]=-1; DP(t,0); DFS(m,0); sort(tmp.begin(),tmp.end()); int top=n,bot=0,mid,ans; while(top>=bot){ mid=top+bot>>1; if(Check(mid))ans=mid,top=mid-1; else bot=mid+1; } printf("%i\n",ans); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 14 ms | 23808 KB | Output is correct |
2 | Correct | 14 ms | 23808 KB | Output is correct |
3 | Correct | 14 ms | 23808 KB | Output is correct |
4 | Correct | 14 ms | 23808 KB | Output is correct |
5 | Correct | 14 ms | 23808 KB | Output is correct |
6 | Correct | 14 ms | 23808 KB | Output is correct |
7 | Correct | 13 ms | 23808 KB | Output is correct |
8 | Correct | 14 ms | 23808 KB | Output is correct |
9 | Correct | 14 ms | 23808 KB | Output is correct |
10 | Correct | 14 ms | 23808 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 457 ms | 72344 KB | Output is correct |
2 | Correct | 415 ms | 67576 KB | Output is correct |
3 | Correct | 970 ms | 73572 KB | Output is correct |
4 | Correct | 448 ms | 48448 KB | Output is correct |
5 | Correct | 991 ms | 73448 KB | Output is correct |
6 | Correct | 998 ms | 73464 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 14 ms | 23808 KB | Output is correct |
2 | Correct | 14 ms | 23808 KB | Output is correct |
3 | Correct | 14 ms | 23808 KB | Output is correct |
4 | Correct | 14 ms | 23808 KB | Output is correct |
5 | Correct | 14 ms | 23808 KB | Output is correct |
6 | Correct | 14 ms | 23808 KB | Output is correct |
7 | Correct | 13 ms | 23808 KB | Output is correct |
8 | Correct | 14 ms | 23808 KB | Output is correct |
9 | Correct | 14 ms | 23808 KB | Output is correct |
10 | Correct | 14 ms | 23808 KB | Output is correct |
11 | Correct | 15 ms | 23808 KB | Output is correct |
12 | Correct | 15 ms | 23808 KB | Output is correct |
13 | Correct | 16 ms | 23808 KB | Output is correct |
14 | Correct | 16 ms | 23936 KB | Output is correct |
15 | Correct | 17 ms | 23936 KB | Output is correct |
16 | Correct | 15 ms | 23808 KB | Output is correct |
17 | Correct | 16 ms | 23808 KB | Output is correct |
18 | Correct | 15 ms | 23936 KB | Output is correct |
19 | Correct | 15 ms | 23936 KB | Output is correct |
20 | Correct | 15 ms | 23936 KB | Output is correct |
21 | Correct | 15 ms | 23936 KB | Output is correct |
22 | Correct | 15 ms | 23808 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 14 ms | 23808 KB | Output is correct |
2 | Correct | 14 ms | 23808 KB | Output is correct |
3 | Correct | 14 ms | 23808 KB | Output is correct |
4 | Correct | 14 ms | 23808 KB | Output is correct |
5 | Correct | 14 ms | 23808 KB | Output is correct |
6 | Correct | 14 ms | 23808 KB | Output is correct |
7 | Correct | 13 ms | 23808 KB | Output is correct |
8 | Correct | 14 ms | 23808 KB | Output is correct |
9 | Correct | 14 ms | 23808 KB | Output is correct |
10 | Correct | 14 ms | 23808 KB | Output is correct |
11 | Correct | 457 ms | 72344 KB | Output is correct |
12 | Correct | 415 ms | 67576 KB | Output is correct |
13 | Correct | 970 ms | 73572 KB | Output is correct |
14 | Correct | 448 ms | 48448 KB | Output is correct |
15 | Correct | 991 ms | 73448 KB | Output is correct |
16 | Correct | 998 ms | 73464 KB | Output is correct |
17 | Correct | 15 ms | 23808 KB | Output is correct |
18 | Correct | 15 ms | 23808 KB | Output is correct |
19 | Correct | 16 ms | 23808 KB | Output is correct |
20 | Correct | 16 ms | 23936 KB | Output is correct |
21 | Correct | 17 ms | 23936 KB | Output is correct |
22 | Correct | 15 ms | 23808 KB | Output is correct |
23 | Correct | 16 ms | 23808 KB | Output is correct |
24 | Correct | 15 ms | 23936 KB | Output is correct |
25 | Correct | 15 ms | 23936 KB | Output is correct |
26 | Correct | 15 ms | 23936 KB | Output is correct |
27 | Correct | 15 ms | 23936 KB | Output is correct |
28 | Correct | 15 ms | 23808 KB | Output is correct |
29 | Correct | 17 ms | 23840 KB | Output is correct |
30 | Correct | 487 ms | 72392 KB | Output is correct |
31 | Correct | 459 ms | 72540 KB | Output is correct |
32 | Correct | 564 ms | 202616 KB | Output is correct |
33 | Correct | 537 ms | 197944 KB | Output is correct |
34 | Correct | 1026 ms | 73720 KB | Output is correct |
35 | Correct | 1025 ms | 73732 KB | Output is correct |
36 | Correct | 1052 ms | 91992 KB | Output is correct |
37 | Correct | 1080 ms | 91928 KB | Output is correct |
38 | Correct | 854 ms | 90672 KB | Output is correct |
39 | Correct | 851 ms | 90736 KB | Output is correct |
40 | Correct | 866 ms | 90740 KB | Output is correct |