제출 #42018

#제출 시각아이디문제언어결과실행 시간메모리
42018fest구슬과 끈 (APIO14_beads)C++14
28 / 100
1080 ms5504 KiB
// fest #include <bits/stdc++.h> #define pb push_back #define F first #define S second #define y1 dasdasfasfas #define x1 wqdadfasfasfas #define All(c) c.begin(), c.end() #define SZ(A) (int((A).size())) #define umap unordered_map #define FILENAME "" #define __ fflush(stdout) typedef long long ll; typedef long double ld; using namespace std; void FREOPEN() { #ifdef COMP freopen(".in", "r", stdin); freopen("1.out", "w", stdout); #endif } inline double Time() {return (clock() * 1.0) / CLOCKS_PER_SEC; } const int N = 200500, inf = 1e9 * 2, MOD = (int)1e9 + 7; char CH[N]; const ll INF = 1e18; const int dx[] = {1, -1, 0, 0, -1, 1, -1, 1}; const int dy[] = {0, 0, 1, -1, -1, 1, 1, -1}; int dp[N][2]; vector<pair<int, int> > g[N]; void dfs(int v, int pr, int last) { dp[v][0] = 0; dp[v][1] = -inf; for (auto i : g[v]) { int u = i.F; int c = i.S; if (u == pr) continue; dfs(u, v, c); dp[v][0] += max(dp[u][0], dp[u][1]); } for (auto i : g[v]) { int u = i.F; int c = i.S; if (u == pr) continue; dp[v][1] = max(dp[v][1], last + (dp[v][0] - max(dp[u][0], dp[u][1])) + c + dp[u][0]); } } int main() { FREOPEN(); int n; cin >> n; for (int i = 2; i <= n; i++) { int x, y, c; scanf("%d %d %d", &x, &y, &c); g[x].pb({y, c}); g[y].pb({x, c}); } int ans = 0; for (int root = 1; root <= n; root++) { dfs(root, 0, 0); ans = max(ans, dp[root][0]); } cout << ans; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

beads.cpp: In function 'int main()':
beads.cpp:67:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d", &x, &y, &c);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...