# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
309580 | 2020-10-03T20:20:13 Z | bigg | Mousetrap (CEOI17_mousetrap) | C++14 | 924 ms | 60280 KB |
#include<bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 10; vector<int> grafo[MAXN]; int dp[MAXN]; pair<int, int > inserts(int x, pair<int, int> p){ if(x >= p.first) swap(p.first, p.second), p.first = x; else if(x > p.second) p.second = x; return p; } void dfs(int x, int p){ pair<int, int> par = make_pair(-1, -1); for(int i = 0; i < grafo[x].size(); i++){ int viz = grafo[x][i]; if(viz == p) continue; dfs(viz, x); par = inserts(dp[viz], par); } for(int i = 0 ; i < grafo[x].size(); i++){ int viz = grafo[x][i]; if(viz == p) swap(grafo[x][i], grafo[x].front()); } if(grafo[x].size() == 1) dp[x] = 0; else{ dp[x] = (grafo[x].size() == 2) ? 1 : par.second + grafo[x].size() - 1; } //printf("%d\n", dp[x]); } int n, t, m; int main(){ scanf("%d %d %d", &n, &t, &m); if(n == 1 || t == m){ printf("0\n"); return 0; } for(int i = 1; i < n; i++){ int u, v; scanf("%d %d", &u, &v); grafo[u].push_back(v); grafo[v].push_back(u); } dfs(t, 0); // printf("oi\n"); int ans = dp[m]; m = grafo[m][0]; // printf("%d\n",m ); while(m != t){ //printf("%d\n", m); ans += grafo[m].size() - 2; m = grafo[m][0]; } printf("%d\n",ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 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 | 16 ms | 23936 KB | Output is correct |
7 | Correct | 14 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 | 14 ms | 23808 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 414 ms | 59000 KB | Output is correct |
2 | Correct | 369 ms | 55508 KB | Output is correct |
3 | Correct | 924 ms | 60248 KB | Output is correct |
4 | Correct | 437 ms | 41976 KB | Output is correct |
5 | Correct | 923 ms | 60280 KB | Output is correct |
6 | Correct | 922 ms | 60096 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 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 | 16 ms | 23936 KB | Output is correct |
7 | Correct | 14 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 | 14 ms | 23808 KB | Output is correct |
11 | Incorrect | 14 ms | 23808 KB | Output isn't correct |
12 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 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 | 16 ms | 23936 KB | Output is correct |
7 | Correct | 14 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 | 14 ms | 23808 KB | Output is correct |
11 | Correct | 414 ms | 59000 KB | Output is correct |
12 | Correct | 369 ms | 55508 KB | Output is correct |
13 | Correct | 924 ms | 60248 KB | Output is correct |
14 | Correct | 437 ms | 41976 KB | Output is correct |
15 | Correct | 923 ms | 60280 KB | Output is correct |
16 | Correct | 922 ms | 60096 KB | Output is correct |
17 | Incorrect | 14 ms | 23808 KB | Output isn't correct |
18 | Halted | 0 ms | 0 KB | - |