# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
284304 | 2020-08-27T08:00:49 Z | BeanZ | Mousetrap (CEOI17_mousetrap) | C++14 | 1143 ms | 70184 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, ban = 0; 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, ll cnt){ dp[u] = 0; vector<ll> val; for (auto j : node[u]){ if (j == p || j == ban) continue; dfs(j, u, 1); val.push_back(dp[j] + 1); } if (val.size()){ sort(val.begin(), val.end()); dp[u] += min((ll)val.size(), cnt); if (val.size() > cnt) dp[u] += val[val.size() - cnt - 1]; dp[u] += max(0, (ll)val.size() - cnt - 1); //cout << u << " " << dp[u] << endl; } } 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); ll ans = 0; ll cnt = 0; while (true){ if (m == t) break; ll preans = 0; dfs(m, par[m], cnt + 1); ll cur = par[m]; preans = dp[m]; while (cur != t){ preans = preans + node[cur].size() - 2; cur = par[cur]; } //cout << preans << " " << dp[m] << endl; ans = max(ans, preans - (cnt > 0)); cnt++; ban = m; m = par[m]; } 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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 17 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 | Correct | 18 ms | 23808 KB | Output is correct |
5 | Correct | 16 ms | 23808 KB | Output is correct |
6 | Correct | 17 ms | 23824 KB | Output is correct |
7 | Correct | 17 ms | 23808 KB | Output is correct |
8 | Correct | 16 ms | 23808 KB | Output is correct |
9 | Correct | 16 ms | 23808 KB | Output is correct |
10 | Correct | 16 ms | 23808 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 402 ms | 67200 KB | Output is correct |
2 | Correct | 430 ms | 62968 KB | Output is correct |
3 | Correct | 1141 ms | 70184 KB | Output is correct |
4 | Correct | 545 ms | 49272 KB | Output is correct |
5 | Correct | 1143 ms | 69496 KB | Output is correct |
6 | Correct | 1126 ms | 69496 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 17 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 | Correct | 18 ms | 23808 KB | Output is correct |
5 | Correct | 16 ms | 23808 KB | Output is correct |
6 | Correct | 17 ms | 23824 KB | Output is correct |
7 | Correct | 17 ms | 23808 KB | Output is correct |
8 | Correct | 16 ms | 23808 KB | Output is correct |
9 | Correct | 16 ms | 23808 KB | Output is correct |
10 | Correct | 16 ms | 23808 KB | Output is correct |
11 | Incorrect | 17 ms | 23808 KB | Output isn't correct |
12 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 17 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 | Correct | 18 ms | 23808 KB | Output is correct |
5 | Correct | 16 ms | 23808 KB | Output is correct |
6 | Correct | 17 ms | 23824 KB | Output is correct |
7 | Correct | 17 ms | 23808 KB | Output is correct |
8 | Correct | 16 ms | 23808 KB | Output is correct |
9 | Correct | 16 ms | 23808 KB | Output is correct |
10 | Correct | 16 ms | 23808 KB | Output is correct |
11 | Correct | 402 ms | 67200 KB | Output is correct |
12 | Correct | 430 ms | 62968 KB | Output is correct |
13 | Correct | 1141 ms | 70184 KB | Output is correct |
14 | Correct | 545 ms | 49272 KB | Output is correct |
15 | Correct | 1143 ms | 69496 KB | Output is correct |
16 | Correct | 1126 ms | 69496 KB | Output is correct |
17 | Incorrect | 17 ms | 23808 KB | Output isn't correct |
18 | Halted | 0 ms | 0 KB | - |