# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
303965 | 2020-09-20T20:42:14 Z | peuch | Mousetrap (CEOI17_mousetrap) | C++17 | 1062 ms | 81272 KB |
#include<bits/stdc++.h> using namespace std; const int MAXN = 1000010; int n, t, m; int pai[MAXN]; int dp[MAXN], marc[MAXN]; int ans; vector<int> ar[MAXN]; void dfs(int cur); void getDP(int cur); int main(){ scanf("%d %d %d", &n, &t, &m); for(int i = 1; i < n; i++){ int a, b; scanf("%d %d", &a, &b); ar[a].push_back(b); ar[b].push_back(a); } dfs(t); while(m != t){ getDP(m); ans += dp[m]; m = pai[m]; } printf("%d\n", ans); } void dfs(int cur){ for(int i = 0; i < ar[cur].size(); i++){ int viz = ar[cur][i]; if(viz == pai[cur]) continue; pai[viz] = cur; dfs(viz); } } void getDP(int cur){ marc[cur] = 1; pair<int, int> aux = make_pair(0, 0); int tam = 0; for(int i = 0; i < ar[cur].size(); i++){ int viz = ar[cur][i]; if(viz == pai[cur]) continue; if(marc[viz]) continue; getDP(viz); if(dp[viz] > aux.first) aux.second = aux.first, aux.first = dp[viz]; else aux.second = max(aux.second, dp[viz]); tam++; } dp[cur] = aux.second + 1 + tam - 1; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 23808 KB | Output is correct |
2 | Correct | 16 ms | 23808 KB | Output is correct |
3 | Correct | 16 ms | 23888 KB | Output is correct |
4 | Correct | 16 ms | 23780 KB | Output is correct |
5 | Incorrect | 16 ms | 23808 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 459 ms | 78092 KB | Output is correct |
2 | Correct | 403 ms | 74488 KB | Output is correct |
3 | Correct | 1061 ms | 81144 KB | Output is correct |
4 | Correct | 508 ms | 52344 KB | Output is correct |
5 | Correct | 1062 ms | 81144 KB | Output is correct |
6 | Correct | 1058 ms | 81272 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 23808 KB | Output is correct |
2 | Correct | 16 ms | 23808 KB | Output is correct |
3 | Correct | 16 ms | 23888 KB | Output is correct |
4 | Correct | 16 ms | 23780 KB | Output is correct |
5 | Incorrect | 16 ms | 23808 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 23808 KB | Output is correct |
2 | Correct | 16 ms | 23808 KB | Output is correct |
3 | Correct | 16 ms | 23888 KB | Output is correct |
4 | Correct | 16 ms | 23780 KB | Output is correct |
5 | Incorrect | 16 ms | 23808 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |