Submission #763964

#TimeUsernameProblemLanguageResultExecution timeMemory
763964pavementTorrent (COI16_torrent)C++17
31 / 100
2058 ms29256 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define int long long #define mp make_pair #define mt make_tuple #define pb push_back #define ppb pop_back #define eb emplace_back #define g0(a) get<0>(a) #define g1(a) get<1>(a) #define g2(a) get<2>(a) #define g3(a) get<3>(a) #define g4(a) get<4>(a) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); using db = double; using ll = long long; using ld = long double; using ii = pair<int, int>; using iii = tuple<int, int, int>; using iiii = tuple<int, int, int, int>; using iiiii = tuple<int, int, int, int, int>; template<class key, class value = null_type, class cmp = less<key> > using ordered_set = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>; int n, a, b, ans = LLONG_MAX, u[300005], v[300005]; bool mrk[300005]; vector<int> edges; vector<ii> adj[300005]; void col(int u, bool c, int x, int e = -1) { mrk[u] = c; for (auto [v, idx] : adj[u]) if (v != e && idx != x) { col(v, c, x, u); } } int dp(int n, int e = -1) { vector<int> vec; int ret = 0; for (auto [u, _] : adj[n]) if (u != e && mrk[n] == mrk[u]) { vec.pb(dp(u, n)); } sort(vec.begin(), vec.end(), greater<int>()); for (int i = 0; i < (int)vec.size(); i++) { ret = max(ret, vec[i] + i + 1); } return ret; } int split(int x) { col(a, 0, x); col(b, 1, x); return max(dp(a), dp(b)); } bool get_edges(int u, int ed, int e = -1) { if (u == ed) return 1; for (auto [v, idx] : adj[u]) if (v != e) { if (get_edges(v, ed, u)) { edges.pb(idx); return 1; } } return 0; } main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> a >> b; for (int i = 1; i < n; i++) { cin >> u[i] >> v[i]; adj[u[i]].eb(v[i], i); adj[v[i]].eb(u[i], i); } get_edges(a, b); int ans = LLONG_MAX; for (int i = 0; i < edges.size(); i++) { ans = min(ans, split(edges[i])); } cout << ans << '\n'; }

Compilation message (stderr)

torrent.cpp:70:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   70 | main() {
      | ^~~~
torrent.cpp: In function 'int main()':
torrent.cpp:81:20: 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]
   81 |  for (int i = 0; i < edges.size(); i++) {
      |                  ~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...