Submission #934539

# Submission time Handle Problem Language Result Execution time Memory
934539 2024-02-27T14:29:37 Z Amirreza_Fakhri Mousetrap (CEOI17_mousetrap) C++17
0 / 100
845 ms 116900 KB
// In the name of the God
#include <bits/stdc++.h>
#define ll long long
// #define int long long
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define pii pair <int, int>
#define smin(x, y) (x) = min((x), (y))
#define smax(x, y) (x) = max((x), (y))
#define all(x) (x).begin(), (x).end()
using namespace std;

const int inf = 1e9+7;
const int mod = 998244353;
const int maxn = 1e6+5;

int n, t, m, par[maxn], dp[maxn];
vector <int> adj[maxn], vec[maxn];

void dfs1(int v, int p) {
    par[v] = p;
    for (int u : adj[v]) {
        if (u != p) {
            dfs1(u, v);
            dp[v]++;
            vec[v].pb(dp[u]);
        }
    }
    sort(all(vec[v]), greater<int>());
    for (int i = 1; i < vec[v].size(); i += 2) dp[v] += vec[v][i];
}

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> t >> m; t--, m--;
    for (int i = 1; i < n; i++) {
        int v, u; cin >> v >> u;
        adj[--v].pb(--u);
        adj[u].pb(v);
    }
    dfs1(t, t);
    int ans = 0, last = -1;
    while (m != t) {
        vec[m].clear();
        for (int u : adj[m]) {
            if (u != par[m] and u != last) {
                vec[m].pb(dp[u]);
                ans++;
            }
        }
        sort(all(vec[m]), greater<int>());
        for (int i = 1; i < vec[m].size(); i += 2) ans += vec[m][i];
        last = m;
        m = par[m];
    }
    cout << ans << '\n';
    return 0;
}





Compilation message

mousetrap.cpp: In function 'void dfs1(int, int)':
mousetrap.cpp:32:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     for (int i = 1; i < vec[v].size(); i += 2) dp[v] += vec[v][i];
      |                     ~~^~~~~~~~~~~~~~~
mousetrap.cpp: In function 'int32_t main()':
mousetrap.cpp:54:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |         for (int i = 1; i < vec[m].size(); i += 2) ans += vec[m][i];
      |                         ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 14 ms 47708 KB Output is correct
2 Correct 15 ms 49892 KB Output is correct
3 Correct 12 ms 49756 KB Output is correct
4 Correct 14 ms 49832 KB Output is correct
5 Incorrect 12 ms 49756 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 298 ms 115364 KB Output is correct
2 Correct 256 ms 109104 KB Output is correct
3 Incorrect 845 ms 116900 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 47708 KB Output is correct
2 Correct 15 ms 49892 KB Output is correct
3 Correct 12 ms 49756 KB Output is correct
4 Correct 14 ms 49832 KB Output is correct
5 Incorrect 12 ms 49756 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 47708 KB Output is correct
2 Correct 15 ms 49892 KB Output is correct
3 Correct 12 ms 49756 KB Output is correct
4 Correct 14 ms 49832 KB Output is correct
5 Incorrect 12 ms 49756 KB Output isn't correct
6 Halted 0 ms 0 KB -