# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
56069 | 2018-07-09T19:49:44 Z | gabrielsimoes | Mousetrap (CEOI17_mousetrap) | C++17 | 51 ms | 13024 KB |
#include <bits/stdc++.h> using namespace std; typedef pair<int,int> pii; const int MAXN = 1e5+10, MAXL = 18; int n, t, s; vector<int> g[MAXN]; bool good[MAXN]; void dfs0(int cur, int pre) { for (int nx : g[cur]) { if (nx != pre) { dfs0(nx, cur); good[cur] |= good[nx]; } } } int ans[MAXN]; void dfs1(int cur, int pre) { if (cur == t) return; int ansGood = -1; vector<int> v; for (int nx : g[cur]) { if (nx != pre) { dfs1(nx, cur); 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; } 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; dfs0(s, s); dfs1(s, s); printf("%d\n", ans[s]); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 2680 KB | Output is correct |
2 | Correct | 4 ms | 2792 KB | Output is correct |
3 | Correct | 4 ms | 2904 KB | Output is correct |
4 | Correct | 3 ms | 2904 KB | Output is correct |
5 | Incorrect | 4 ms | 2908 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 51 ms | 13024 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 2680 KB | Output is correct |
2 | Correct | 4 ms | 2792 KB | Output is correct |
3 | Correct | 4 ms | 2904 KB | Output is correct |
4 | Correct | 3 ms | 2904 KB | Output is correct |
5 | Incorrect | 4 ms | 2908 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 2680 KB | Output is correct |
2 | Correct | 4 ms | 2792 KB | Output is correct |
3 | Correct | 4 ms | 2904 KB | Output is correct |
4 | Correct | 3 ms | 2904 KB | Output is correct |
5 | Incorrect | 4 ms | 2908 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |