# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1024172 |
2024-07-15T14:33:04 Z |
pan |
Training (IOI07_training) |
C++17 |
|
15 ms |
9820 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[100005];
vector<pii> forlca[100005], up;
ll depth[100005];
ll deg[100005];
pi par[100005];
ll dp[5005][5005];
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 |
2 ms |
5208 KB |
Output is correct |
2 |
Correct |
2 ms |
5232 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5212 KB |
Output is correct |
2 |
Correct |
2 ms |
5212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
9304 KB |
Output is correct |
2 |
Correct |
8 ms |
9308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5212 KB |
Output is correct |
2 |
Correct |
3 ms |
5212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5212 KB |
Output is correct |
2 |
Correct |
3 ms |
5212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
5468 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
6236 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
7208 KB |
Output is correct |
2 |
Incorrect |
3 ms |
7260 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9564 KB |
Output is correct |
2 |
Correct |
6 ms |
9820 KB |
Output is correct |
3 |
Incorrect |
6 ms |
9448 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7516 KB |
Output is correct |
2 |
Correct |
4 ms |
7260 KB |
Output is correct |
3 |
Correct |
14 ms |
9708 KB |
Output is correct |
4 |
Incorrect |
5 ms |
7260 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
9560 KB |
Output is correct |
2 |
Correct |
15 ms |
9640 KB |
Output is correct |
3 |
Correct |
8 ms |
9564 KB |
Output is correct |
4 |
Correct |
7 ms |
9820 KB |
Output is correct |