제출 #83175

#제출 시각아이디문제언어결과실행 시간메모리
83175RezwanArefin01구슬과 끈 (APIO14_beads)C++17
28 / 100
1079 ms10112 KiB
///usr/bin/g++ -O2 $0 -o ${0%.cpp} && echo "----------" && ./${0%.cpp}; exit; #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 2e5 + 10; vector<int> adj[N], cost[N]; ll dp[N][2]; ll f(int u, int par, bool c) { if(par && adj[u].size() == 1) { if(c) return -1e18; else return 0; } ll &ret = dp[u][c]; if(~ret) return ret; ret = 0; ll sum = 0; for(int i = 0; i < adj[u].size(); i++) { int v = adj[u][i], c = cost[u][i]; if(v == par) continue; sum += max(f(v, u, 0), f(v, u, 1) + c); } if(!c) return ret = sum; for(int i = 0; i < adj[u].size(); i++) { int v = adj[u][i], c = cost[u][i]; if(v == par) continue; ll cont = max(f(v, u, 0), f(v, u, 1) + c); ret = max(ret, sum - cont + f(v, u, 0) + c); } return ret; } int main() { int n; scanf("%d", &n); for(int i = 1; i < n; i++) { int u, v, c; scanf("%d %d %d", &u, &v, &c); adj[u].push_back(v); adj[v].push_back(u); cost[u].push_back(c); cost[v].push_back(c); } ll ans = 0; for(int i = 1; i <= n; i++) { for(int j = 1; j <= n; j++) dp[j][0] = dp[j][1] = -1; ans = max(ans, f(i, 0, 0)); } printf("%lld\n", ans); }

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

beads.cpp: In function 'll f(int, int, bool)':
beads.cpp:21:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < adj[u].size(); i++) {
                    ~~^~~~~~~~~~~~~~~
beads.cpp:29:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < adj[u].size(); i++) {
                    ~~^~~~~~~~~~~~~~~
beads.cpp: In function 'int main()':
beads.cpp:39:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     int n; scanf("%d", &n);
            ~~~~~^~~~~~~~~~
beads.cpp:42:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d", &u, &v, &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...