Submission #934541

#TimeUsernameProblemLanguageResultExecution timeMemory
934541Amirreza_FakhriMousetrap (CEOI17_mousetrap)C++17
0 / 100
734 ms119196 KiB
// 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 (stderr)

mousetrap.cpp: In function 'void dfs1(long long int, long long int)':
mousetrap.cpp:32:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long 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: 'long long int' and 'std::vector<long long 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...