Submission #763960

# Submission time Handle Problem Language Result Execution time Memory
763960 2023-06-23T04:06:47 Z pavement Torrent (COI16_torrent) C++17
0 / 100
2000 ms 120184 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<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);
	}
	cout << "DP " << n << ' ' << ret << '\n';
	return ret;
}

int split(int x) {
	col(a, 0, x);
	col(b, 1, x);
	for (int i = 1; i <= n; i++) {
		cout << mrk[i];
	}
	cout << '\n';
	return max(dp(a), dp(b));
}

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);
	}
	for (int i = 1; i < n; i++) {
		cout << i << ": " << split(i) << '\n';
		ans = min(ans, split(i));
	}
	cout << ans << '\n';
}

Compilation message

torrent.cpp:63:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   63 | main() {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 718 ms 44416 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2069 ms 120184 KB Time limit exceeded
2 Halted 0 ms 0 KB -