제출 #372658

#제출 시각아이디문제언어결과실행 시간메모리
372658hivakarami구슬과 끈 (APIO14_beads)C++14
0 / 100
1 ms492 KiB
#include<bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; #define f first #define s second const int N = 100 + 100; const int K = 1000 + 100; const ll mod = 998244353; const ll inf = 1e9 + 100; ll dp[2][N], w[N][N], par[N]; vector<int> adj[N]; int n; void dfs(int u) { dp[1][u] = 0; for(auto x : adj[u]) { if(x != par[u]) { par[x] = u; dfs(x); dp[1][u] += min(dp[1][x] + w[x][u], dp[2][x]); } } dp[2][u] = inf; for(auto x : adj[u]) { if(x != par[u]) { ll mn = min(dp[1][x] + w[x][u], dp[2][x]); dp[2][u] = min(dp[2][u], dp[1][u] - mn + dp[1][x]); } } //cout << u << ' ' << dp[1][u] << ' ' << dp[2][u] << endl; } inline void cl() { for(int i = 0; i < n; i++) par[i] = i; } int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> n; ll sum = 0; for(int i = 0; i < n-1; i++) { int x, y; cin >> x >> y; x--; y--; cin >> w[x][y]; adj[x].push_back(y); adj[y].push_back(x); w[y][x] = w[x][y]; sum += w[x][y]; } ll ans = inf; for(int i = 0; i < n; i++) { cl(); dfs(i); ans = min(ans, dp[1][i]); } cout << sum - ans << endl; return 0; }

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

beads.cpp: In function 'void dfs(int)':
beads.cpp:32:6: warning: array subscript 2 is above array bounds of 'll [2][200]' {aka 'long long int [2][200]'} [-Warray-bounds]
   32 |  dp[2][u] = inf;
      |  ~~~~^
beads.cpp:15:4: note: while referencing 'dp'
   15 | ll dp[2][N], w[N][N], par[N];
      |    ^~
beads.cpp:37:40: warning: array subscript 2 is above array bounds of 'll [2][200]' {aka 'long long int [2][200]'} [-Warray-bounds]
   37 |    ll mn = min(dp[1][x] + w[x][u], dp[2][x]);
      |                                    ~~~~^
beads.cpp:38:23: warning: array subscript 2 is above array bounds of 'll [2][200]' {aka 'long long int [2][200]'} [-Warray-bounds]
   38 |    dp[2][u] = min(dp[2][u], dp[1][u] - mn + dp[1][x]);
      |                   ~~~~^
beads.cpp:38:8: warning: array subscript 2 is above array bounds of 'll [2][200]' {aka 'long long int [2][200]'} [-Warray-bounds]
   38 |    dp[2][u] = min(dp[2][u], dp[1][u] - mn + dp[1][x]);
      |    ~~~~^
beads.cpp:15:4: note: while referencing 'dp'
   15 | ll dp[2][N], w[N][N], par[N];
      |    ^~
beads.cpp:28:44: warning: array subscript 2 is above array bounds of 'll [2][200]' {aka 'long long int [2][200]'} [-Warray-bounds]
   28 |    dp[1][u] += min(dp[1][x] + w[x][u], dp[2][x]);
      |                                        ~~~~^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...