Submission #937545

#TimeUsernameProblemLanguageResultExecution timeMemory
937545IBoryTraining (IOI07_training)C++17
100 / 100
56 ms9176 KiB
#include <bits/stdc++.h> #define pii pair<int, int> using namespace std; const int MAX = 5005, BIT = 1 << 10; vector<int> G[MAX], T[MAX]; pii E[MAX]; int P[MAX], D[MAX], C[MAX], R[MAX], idx[BIT][BIT], dp[BIT][BIT]; int in[MAX], out[MAX], dn; void DFS(int cur, int prev) { if (prev) G[cur].erase(find(G[cur].begin(), G[cur].end(), prev)); in[cur] = ++dn; D[cur] = D[prev] + 1; P[cur] = prev; for (int next : G[cur]) DFS(next, cur); out[cur] = dn; } int LCA(int a, int b) { if (D[a] > D[b]) swap(a, b); while (D[a] != D[b]) b = P[b]; while (a != b) a = P[a], b = P[b]; return a; } int Find(int cur, int child) { for (int i = 0; i < G[cur].size(); ++i) { int n = G[cur][i]; if (in[n] <= in[child] && in[child] <= out[n]) return (1 << i); } return 0; } int Update(int p, int cur) { int c = 0, ret = 0; while (1) { ret += dp[cur][1023 - idx[cur][c]]; c = cur; if (p == cur) return ret; cur = P[cur]; } } void DFS2(int cur) { for (int next : G[cur]) DFS2(next); vector<pii> cost; for (int i = 0; i < G[cur].size(); ++i) { cost.emplace_back(1 << i, dp[G[cur][i]][1023]); } for (int i = G[cur].size(); i < 10; ++i) { cost.emplace_back(1 << i, 0); } for (int en : T[cur]) { auto [a, b] = E[en]; int bit = 0, v = C[en]; if (a != cur) bit |= Find(cur, a), v += Update(R[en], a); if (b != cur) bit |= Find(cur, b), v += Update(R[en], b); cost.emplace_back(bit, v); } for (int i = 0; i < BIT; ++i) { for (auto [b, n] : cost) { if (i & b) continue; dp[cur][i | b] = max(dp[cur][i | b], dp[cur][i] + n); } } // cout << cur << ' ' << dp[cur][1023] << '\n'; } int main() { ios::sync_with_stdio(0); cin.tie(0); int N, M, ans = 0, remain = 1; cin >> N >> M; for (int i = 1; i <= M; ++i) { int a, b, c; cin >> a >> b >> c; if (!c) { G[a].push_back(b); G[b].push_back(a); } else { E[remain] = {a, b}; C[remain++] = c; ans += c; } } DFS(1, 0); for (int i = 1; i <= M - N + 1; ++i) { auto [a, b] = E[i]; if (abs(D[a] - D[b]) & 1) continue; R[i] = LCA(a, b); T[R[i]].push_back(i); } for (int i = 1; i <= N; ++i) for (int j = 0; j < G[i].size(); ++j) idx[i][G[i][j]] = 1 << j; DFS2(1); ans -= dp[1][1023]; cout << ans; return 0; }

Compilation message (stderr)

training.cpp: In function 'int Find(int, int)':
training.cpp:28:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |  for (int i = 0; i < G[cur].size(); ++i) {
      |                  ~~^~~~~~~~~~~~~~~
training.cpp: In function 'void DFS2(int)':
training.cpp:49:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |  for (int i = 0; i < G[cur].size(); ++i) {
      |                  ~~^~~~~~~~~~~~~~~
training.cpp: In function 'int main()':
training.cpp:99:49: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   99 |  for (int i = 1; i <= N; ++i) for (int j = 0; j < G[i].size(); ++j) idx[i][G[i][j]] = 1 << j;
      |                                               ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...