# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
56072 | 2018-07-09T20:08:12 Z | gabrielsimoes | Mousetrap (CEOI17_mousetrap) | C++17 | 1141 ms | 61548 KB |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6+10; int n, t, s; vector<int> g[MAXN]; bool good[MAXN]; int ans[MAXN]; void dfs(int cur, int pre) { if (cur == t) return; int ansGood = 0; vector<int> v; for (int nx : g[cur]) { if (nx != pre) { dfs(nx, cur); good[cur] |= good[nx]; if (good[nx]) ansGood = ans[nx]; else v.push_back(ans[nx]); } } sort(v.rbegin(), v.rend()); int &ret = ans[cur]; for (int i = 0; i < v.size(); i++) { if (i % 2) ret += v[i]; else ret++; } if (!good[cur]) ret++; else ret += ansGood; // printf("ans[%d] == %d\n", cur, ans[cur]); } int main() { scanf("%d %d %d", &n, &t, &s); for (int i = 1,a,b; i < n; i++) { scanf("%d %d", &a, &b); g[a].push_back(b); g[b].push_back(a); } good[t] = true; dfs(s, s); printf("%d\n", ans[s]); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 25 ms | 23800 KB | Output is correct |
2 | Correct | 24 ms | 23948 KB | Output is correct |
3 | Correct | 22 ms | 23948 KB | Output is correct |
4 | Correct | 25 ms | 23948 KB | Output is correct |
5 | Incorrect | 20 ms | 23948 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 551 ms | 59788 KB | Output is correct |
2 | Correct | 470 ms | 59788 KB | Output is correct |
3 | Incorrect | 1141 ms | 61548 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 25 ms | 23800 KB | Output is correct |
2 | Correct | 24 ms | 23948 KB | Output is correct |
3 | Correct | 22 ms | 23948 KB | Output is correct |
4 | Correct | 25 ms | 23948 KB | Output is correct |
5 | Incorrect | 20 ms | 23948 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 25 ms | 23800 KB | Output is correct |
2 | Correct | 24 ms | 23948 KB | Output is correct |
3 | Correct | 22 ms | 23948 KB | Output is correct |
4 | Correct | 25 ms | 23948 KB | Output is correct |
5 | Incorrect | 20 ms | 23948 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |