Submission #774619

#TimeUsernameProblemLanguageResultExecution timeMemory
774619TAMREFBeads and wires (APIO14_beads)C++17
0 / 100
2 ms5032 KiB
// C #ifndef _GLIBCXX_NO_ASSERT #include <cassert> #endif #include <cctype> #include <cerrno> #include <cfloat> #include <ciso646> #include <climits> #include <clocale> #include <cmath> #include <csetjmp> #include <csignal> #include <cstdarg> #include <cstddef> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #if __cplusplus >= 201103L #include <ccomplex> #include <cfenv> #include <cinttypes> #include <cstdbool> #include <cstdint> #include <ctgmath> #include <cwchar> #include <cwctype> #endif // C++ #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #if __cplusplus >= 201103L #include <array> #include <atomic> #include <chrono> #include <condition_variable> #include <forward_list> #include <future> #include <initializer_list> #include <mutex> #include <random> #include <ratio> #include <regex> #include <scoped_allocator> #include <system_error> #include <thread> #include <tuple> #include <typeindex> #include <type_traits> #include <unordered_map> #include <unordered_set> #endif #define va first #define vb second #define lb lower_bound #define ub upper_bound #define bs binary_search #define pp push_back #define ep emplace_back #define all(v) (v).begin(),(v).end() #define szz(v) ((int)(v).size()) #define bi_pc __builtin_popcount #define bi_pcll __builtin_popcountll #define bi_tz __builtin_ctz #define bi_tzll __builtin_ctzll #define fio ios_base::sync_with_stdio(0);cin.tie(0); #ifdef TAMREF #define debug(...) fprintf(stderr, __VA_ARGS__) #else #define debug(...) 42 #endif using namespace std; template<typename ...Args> void logger(string vars, Args&&... values) { cerr << vars << " = "; string delim = ""; (..., (cerr << delim << values, delim = ", ")); cerr << '\n'; } #ifdef TAMREF #define deb(...) logger(#__VA_ARGS__, __VA_ARGS__) #else #define deb(...) 42 #endif using ll = long long; using lf = long double; using pii = pair<int,int>; using ppi = pair<int,pii>; using pll = pair<ll,ll>; using pff = pair<lf,lf>; using ti = tuple<int,int,int>; using base = complex<double>; const lf PI = 3.14159265358979323846264338L; template <typename T> inline T umax(T& u, T v){return u = max(u, v);} template <typename T> inline T umin(T& u, T v){return u = min(u, v);} mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); vector<pll> G[200005]; ll dp[200005][2]; int vis[200005]; int n; void dfs(int x) { vis[x] = 1; vector<ll> P(2); P[0] = LLONG_MIN; for(auto &[u, w] : G[x]) { if(vis[u]) continue; dfs(u); for(int b = 0; b < 2; b++) { for(int c = 0; c < 2; c++) { ll cand = dp[u][b] + P[c]; if(b || dp[u][b]) cand += w; umax(dp[x][b ^ c], cand); } } if(dp[u][0]) umax(P[1], dp[u][0] + w); umax(P[0], dp[u][1] + w); } debug("dp[%d][%d] = %lld, dp[%d][%d] = %lld\n", x, 0, dp[x][0], x, 1, dp[x][1]); } int main(){ fio; cin >> n; for(int i = 1, a, b, c; i < n; i++) { cin >> a >> b >> c; G[a].ep(b, c); G[b].ep(a, c); } for(int i = 1; i <= n; i++) { if(szz(G[i]) == 1) { dfs(i); break; } } ll ans = 0; for(int i = 1; i <= n; i++) umax(ans, dp[i][1]); cout << ans << '\n'; }

Compilation message (stderr)

beads.cpp: In function 'void dfs(int)':
beads.cpp:104:20: warning: statement has no effect [-Wunused-value]
  104 | #define debug(...) 42
      |                    ^~
beads.cpp:153:5: note: in expansion of macro 'debug'
  153 |     debug("dp[%d][%d] = %lld, dp[%d][%d] = %lld\n", x, 0, dp[x][0], x, 1, dp[x][1]);
      |     ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...