제출 #48300

#제출 시각아이디문제언어결과실행 시간메모리
48300octopuses구슬과 끈 (APIO14_beads)C++17
28 / 100
1074 ms5504 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], answer; 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; 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}); } for(int i = 1; i <= n; ++ i) { for(int j = 1; j <= n; ++ j) A[j] = B[j] = 0; go(i); answer = max(answer, A[i]); } cout << answer << endl; }

컴파일 시 표준 에러 (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:33: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:44:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &n);
   ~~~~~^~~~~~~~~~
beads.cpp:48: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...