Submission #560239

#TimeUsernameProblemLanguageResultExecution timeMemory
560239hhhhauraBeads and wires (APIO14_beads)C++14
0 / 100
1 ms320 KiB
#define wiwihorz #include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("sse") #pragma loop-opt(on) #define rep(i, a, b) for(int i = a; i <= b; i ++) #define rrep(i, a, b) for(int i = b; i >= a; i --) #define all(x) x.begin(), x.end() #define ceil(a, b) ((a + b - 1) / (b)) #define int long long int #define lld long double #define pii pair<int, int> #define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()) #define INF 1000000000000000000 #define MOD 1000000007 #define eps (1e-9) using namespace std; #ifdef wiwihorz #define print(a...)cerr<<"Line "<<__LINE__<<":",kout("["+string(#a)+"] = ", a) void vprint(auto L,auto R){while(L<R)cerr<<*L<<" \n"[next(L) == R], ++L; } void kout() { cerr << endl; } template<class T1,class ... T2>void kout(T1 a,T2 ... e){cerr<<a<<" ",kout(e...);} #else #define print(...) 0 #define vprint(...) 0 #endif #define x first #define y second namespace solver { int n; vector<int> leaf, dp1, dp2; vector<vector<pii>> mp; void init_(int _n) { n = _n; mp.assign(n + 1, vector<pii>()); } void build() { dp1.assign(n + 1, 0); dp2.assign(n + 1, 0); leaf.assign(n + 1, 1); } void dfs(int x, int par) { int v = -INF, sum = 0, sum1 = 0; for(auto i : mp[x]) if(i.x != par) { dfs(i.x, x); leaf[x] = 0; if(leaf[i.x]) v = max(v, i.y); else { sum += max(dp1[i.x] + i.y, dp2[i.x]); sum1 += dp1[i.x] + i.y; v = max(v, dp2[i.x] - dp1[i.x]); } } dp1[x] = sum1 + v; dp2[x] = sum; } void solve() { int ans = 0; rep(i, 1, n) { build(); dfs(i, i); ans = max(ans, dp2[i]); } cout << ans << "\n"; } }; using namespace solver; signed main() { ios::sync_with_stdio(false), cin.tie(0); int n; cin >> n; init_(n); rep(i, 1, n - 1) { int a, b, c; cin >> a >> b >> c; mp[a].push_back({b, c}); mp[b].push_back({a, c}); } solve(); return 0; }

Compilation message (stderr)

beads.cpp:5: warning: ignoring '#pragma loop ' [-Wunknown-pragmas]
    5 | #pragma loop-opt(on)
      | 
beads.cpp:20:13: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   20 | void vprint(auto L,auto R){while(L<R)cerr<<*L<<" \n"[next(L) == R], ++L; }
      |             ^~~~
beads.cpp:20:20: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   20 | void vprint(auto L,auto R){while(L<R)cerr<<*L<<" \n"[next(L) == R], ++L; }
      |                    ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...