# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
131529 | 2019-07-17T08:49:12 Z | SamAnd | Mousetrap (CEOI17_mousetrap) | C++17 | 1049 ms | 60280 KB |
#include <bits/stdc++.h> using namespace std; const int N = 1000006; int n, t, m; vector<int> a[N]; bool c[N]; void dfs0(int x, int p) { if (x == t) { c[x] = true; return; } for (int i = 0; i < a[x].size(); ++i) { int h = a[x][i]; if (h == p) continue; dfs0(h, x); if (c[h]) { c[x] = true; return; } } } int dp[N]; void dfs(int x, int p) { if (x == t) return; vector<int> v; int vv = 0; for (int i = 0; i < a[x].size(); ++i) { int h = a[x][i]; if (h == p) continue; dfs(h, x); if (!c[h]) v.push_back(dp[h]); } sort(v.begin(), v.end()); for (int i = v.size() - 2; i >= 0; i -= 2) { dp[x] += v[i]; } dp[x] += v.size(); } int main() { //freopen("input.txt", "r", stdin); scanf("%d%d%d", &n, &t, &m); for (int i = 0; i < n - 1; ++i) { int x, y; scanf("%d%d", &x, &y); a[x].push_back(y); a[y].push_back(x); } dfs0(m, m); dfs(m, m); int ans = 0; for (int x = 1; x <= n; ++x) { if (c[x]) ans += dp[x]; } cout << ans << endl; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 23800 KB | Output is correct |
2 | Correct | 24 ms | 23800 KB | Output is correct |
3 | Correct | 24 ms | 23800 KB | Output is correct |
4 | Correct | 24 ms | 23800 KB | Output is correct |
5 | Incorrect | 23 ms | 23800 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 480 ms | 59040 KB | Output is correct |
2 | Correct | 436 ms | 55584 KB | Output is correct |
3 | Incorrect | 1049 ms | 60280 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 23800 KB | Output is correct |
2 | Correct | 24 ms | 23800 KB | Output is correct |
3 | Correct | 24 ms | 23800 KB | Output is correct |
4 | Correct | 24 ms | 23800 KB | Output is correct |
5 | Incorrect | 23 ms | 23800 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 23800 KB | Output is correct |
2 | Correct | 24 ms | 23800 KB | Output is correct |
3 | Correct | 24 ms | 23800 KB | Output is correct |
4 | Correct | 24 ms | 23800 KB | Output is correct |
5 | Incorrect | 23 ms | 23800 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |