# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
284285 | 2020-08-27T07:16:52 Z | BeanZ | Mousetrap (CEOI17_mousetrap) | C++14 | 1123 ms | 81348 KB |
#include <bits/stdc++.h> using namespace std; #define ll int #define endl '\n' const int N = 3e6 + 5; const int mod = 998244353; ll n, t, m; vector<ll> node[1000006]; ll dp[1000006], par[1000006], f[1000006]; void dfsFirst(ll u, ll v){ par[u] = v; for (auto j : node[u]){ if (j == v) continue; dfsFirst(j, u); f[u] |= f[j]; } if (u == m) f[u] = 1; } void dfs(ll u, ll p){ dp[u] = 0; vector<ll> val; for (auto j : node[u]){ if (j == p) continue; dfs(j, u); val.push_back(dp[j] + 1); } if (val.size()){ sort(val.begin(), val.end()); dp[u]++; if (val.size() > 1) dp[u] += val[val.size() - 2]; dp[u] += val.size() - 2; } } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); if (fopen("MOUSETRAP.INP", "r")){ freopen("MOUSETRAP.INP", "r", stdin); freopen("MOUSETRAP.OUT", "w", stdout); } cin >> n >> t >> m; for (int i = 1; i < n; i++){ ll u, v; cin >> u >> v; node[u].push_back(v); node[v].push_back(u); } dfsFirst(t, t); dfs(m, par[m]); ll cur = par[m]; ll ans = dp[m]; while (cur != t){ ans = ans + node[cur].size() - 2; cur = par[cur]; } cout << ans; } /* 13 13 1 1 2 2 3 2 4 1 5 5 6 5 7 1 8 8 9 8 10 1 11 11 12 11 13 10 1 4 1 2 2 3 2 4 3 9 3 5 4 7 4 6 6 8 7 10 14 4 1 1 2 2 5 2 6 5 7 5 8 8 10 6 9 1 3 3 14 3 11 11 12 11 13 1 4 12 12 1 1 2 1 3 3 4 4 5 4 6 3 7 7 8 7 9 3 10 10 11 10 12 */
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 | 23808 KB | Output is correct |
4 | Incorrect | 16 ms | 23808 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 405 ms | 78324 KB | Output is correct |
2 | Correct | 403 ms | 72900 KB | Output is correct |
3 | Correct | 1123 ms | 81348 KB | Output is correct |
4 | Incorrect | 526 ms | 52344 KB | Output isn't correct |
5 | 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 | 23808 KB | Output is correct |
4 | Incorrect | 16 ms | 23808 KB | Output isn't correct |
5 | 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 | 23808 KB | Output is correct |
4 | Incorrect | 16 ms | 23808 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |