Submission #763956

# Submission time Handle Problem Language Result Execution time Memory
763956 2023-06-23T04:02:27 Z pavement Torrent (COI16_torrent) C++17
0 / 100
760 ms 29332 KB
#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, 0), dp(b, 1));
}

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 lo = 1, hi = (int)edges.size() - 1, ans = 0;
	while (lo <= hi) {
		int mid = (lo + hi) / 2;
		if (split(edges[mid]) >= split(edges[mid - 1])) {
			ans = mid;
			hi = mid - 1;
		} else {
			lo = mid + 1;
		}
	}
	cout << min(split(edges[ans]), ans ? split(edges[ans - 1]) : LLONG_MAX) << '\n';
}

Compilation message

torrent.cpp:70:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   70 | main() {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 7380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 760 ms 29332 KB Output isn't correct
2 Halted 0 ms 0 KB -