Submission #1024161

# Submission time Handle Problem Language Result Execution time Memory
1024161 2024-07-15T14:26:58 Z pan Training (IOI07_training) C++17
55 / 100
11 ms 5056 KB
#include <bits/stdc++.h>
//#include "bits_stdc++.h"
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define endl '\n'
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define input(x) scanf("%lld", &x);
#define input2(x, y) scanf("%lld%lld", &x, &y);
#define input3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z);
#define input4(x, y, z, a) scanf("%lld%lld%lld%lld", &x, &y, &z, &a);
#define print(x, y) printf("%lld%c", x, y);
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl;
#define all(x) x.begin(), x.end()
#define discretize(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define FOR(i, x, n) for (ll i =x; i<=n; ++i) 
#define RFOR(i, x, n) for (ll i =x; i>=n; --i) 
using namespace std;
mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());
//using namespace __gnu_pbds;
//#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
//#define ordered_multiset tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
typedef long long ll;
typedef long double ld;
typedef pair<ld, ll> pd;
typedef pair<string, ll> psl;
typedef pair<ll, ll> pi;
typedef pair<pi, ll> pii;
typedef pair<pi, pi> piii;

ll n, m, x, y, z;
vector<ll> adj[1005];
vector<pii> forlca[1005], up;
ll depth[1005];
ll deg[1005];
pi par[1005];
ll dp[1005][1005];

inline ll lca(ll x, ll y)
{
	while (x!=y) 
	{
		if (depth[x] < depth[y]) swap(x,y);
		x = par[x].f;
	} 
	return x;
}


void precomp(ll x, ll p = -1)
{
	deg[x] = 0;
	for (ll u: adj[x])
	{
		if (u==p) continue;
		depth[u] = depth[x] + 1;
		par[u] = mp(x, deg[x]++);
		precomp(u, x);
	}
}

void dfs(ll x, ll p = -1)
{
	for (ll u: adj[x]) if (p!=u) dfs(u, x);
	ll cnt = 0;
	for (ll i=0; i<(1LL << deg[x]); ++i) dp[x][i] = 0;
	for (ll u: adj[x])
	{
		if (p==u) continue;
		for (ll mask=(1LL << deg[x])-1; mask>=0; --mask) 
		{
			if (mask&(1LL << cnt)) continue;
			dp[x][mask] = max(dp[x][mask], dp[u][0]);
		}
		cnt++;
	}
	for (pii u: forlca[x])
	{
		pi uu = mp(u.f.f, -1), vv = mp(u.f.s, -1);
		ll sum = u.s;
		if (u.f.f!=x) sum += dp[u.f.f][0];
		if (u.f.s!=x) sum += dp[u.f.s][0];
		while (uu.f!=x) {uu = par[uu.f]; if (uu.f!=x) sum += dp[uu.f][(1LL << uu.s)];}
		while (vv.f!=x) {vv = par[vv.f]; if (vv.f!=x) sum += dp[vv.f][(1LL << vv.s)];}
		for (ll mask=(1LL << deg[x])-1; mask>=0; --mask) 
		{
			if (mask&(1LL << uu.s) || (mask&(1LL << vv.s))) continue;
			dp[x][mask] = max(dp[x][mask], dp[x][mask^(1LL << uu.s)^(1LL << vv.s)] + sum);
		}
	}
}



int main()
{
	input2(n, m);
	ll sum = 0;
	for (ll i=0; i<m; ++i)
	{
		input3(x, y, z);
		if (z==0) adj[x].pb(y), adj[y].pb(x);
		else up.pb(mp(mp(x, y), z));
		sum += z;
		
	}
	depth[1] = 0, par[1] = mp(-1, 0);
	precomp(1);
	for (pii u: up) 
	{
		ll lc = lca(u.f.f, u.f.s);
		ll dist = depth[u.f.f] + depth[u.f.s] - 2*depth[lc];
		if (dist%2==0) forlca[lca(u.f.f, u.f.s)].pb(u);
		//else show2(u.f.f, u.f.s);
	}
	dfs(1);
	print(sum - dp[1][0], '\n');
	return 0;
}

Compilation message

training.cpp: In function 'int main()':
training.cpp:13:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 | #define input2(x, y) scanf("%lld%lld", &x, &y);
      |                      ~~~~~^~~~~~~~~~~~~~~~~~~~
training.cpp:103:2: note: in expansion of macro 'input2'
  103 |  input2(n, m);
      |  ^~~~~~
training.cpp:14:30: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 | #define input3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z);
      |                         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
training.cpp:107:3: note: in expansion of macro 'input3'
  107 |   input3(x, y, z);
      |   ^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4696 KB Output is correct
2 Correct 6 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 860 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1628 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2648 KB Output is correct
2 Incorrect 2 ms 2652 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4700 KB Output is correct
2 Correct 5 ms 5000 KB Output is correct
3 Incorrect 3 ms 4696 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2652 KB Output is correct
2 Correct 2 ms 2648 KB Output is correct
3 Correct 11 ms 4972 KB Output is correct
4 Incorrect 3 ms 2652 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4952 KB Output is correct
2 Correct 11 ms 4816 KB Output is correct
3 Correct 7 ms 5056 KB Output is correct
4 Correct 5 ms 4956 KB Output is correct