제출 #48299

#제출 시각아이디문제언어결과실행 시간메모리
48299octopuses구슬과 끈 (APIO14_beads)C++17
0 / 100
6 ms4992 KiB
#include <bits/stdc++.h> #define ll long long #define fr first #define sc second #define M (ll)(3e17) using namespace std; const int N = 200020; vector < pair < int, int > > G[N]; int n; ll A[N], B[N]; void go(int v, int p = 0) { ll mx1 = -2e9, mx2 = -2e9, child = 0, tot = 0, par = -2e9; for(int i = 0; i < G[v].size(); ++ i) { int to = G[v][i].first; if(to == p) { par = G[v][i].second; continue; } go(to, v); tot += A[to]; child ++; } B[v] = tot; for(int i = 0; i < G[v].size(); ++ i) { if(G[v][i].first == p) continue; for(int j = i + 1; j < G[v].size(); ++ j) { if(G[v][j].first == p) continue; B[v] = max(B[v], tot + B[G[v][i].first] + B[G[v][j].first] - A[G[v][i].first] - A[G[v][j].first] + G[v][i].second + G[v][j].second); } } A[v] = B[v]; for(int i = 0; i < G[v].size(); ++ i) { int to = G[v][i].first; if(to == p) continue; A[v] = max(A[v], tot - A[to] + B[to] + par + G[v][i].second); } } int main() { scanf("%d", &n); for(int i = 1; i < n; ++ i) { int x, y, val; scanf("%d %d %d", &x, &y, &val); G[x].push_back({y, val}); G[y].push_back({x, val}); } go(1); cout << A[1] << endl; } /* 10 4 10 2 1 2 21 1 3 13 6 7 1 7 9 5 2 4 3 2 5 8 1 6 55 6 8 34 5 1 2 10 1 3 40 1 4 15 1 5 20 */

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

beads.cpp: In function 'void go(int, int)':
beads.cpp:18:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < G[v].size(); ++ i)
                  ~~^~~~~~~~~~~~~
beads.cpp:32:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < G[v].size(); ++ i)
                  ~~^~~~~~~~~~~~~
beads.cpp:36:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int j = i + 1; j < G[v].size(); ++ j)
                        ~~^~~~~~~~~~~~~
beads.cpp:44:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < G[v].size(); ++ i)
                  ~~^~~~~~~~~~~~~
beads.cpp:17:6: warning: unused variable 'mx1' [-Wunused-variable]
   ll mx1 = -2e9, mx2 = -2e9, child = 0, tot = 0, par = -2e9;
      ^~~
beads.cpp:17:18: warning: unused variable 'mx2' [-Wunused-variable]
   ll mx1 = -2e9, mx2 = -2e9, child = 0, tot = 0, par = -2e9;
                  ^~~
beads.cpp: In function 'int main()':
beads.cpp:55:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &n);
   ~~~~~^~~~~~~~~~
beads.cpp:59:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d", &x, &y, &val);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...