제출 #1090903

#제출 시각아이디문제언어결과실행 시간메모리
1090903ttamx도로 폐쇄 (APIO21_roads)C++17
0 / 100
2096 ms22608 KiB
#include "roads.h" #include <bits/stdc++.h> using namespace std; using ll = long long; const int N=1e5+5; int n; vector<pair<int,int>> adj[N]; ll dp[N][2]; void dfs(int u,int p,int k){ ll sum=0; vector<ll> a; for(auto [v,w]:adj[u])if(v!=p){ dfs(v,u,k); sum+=dp[v][0]; a.emplace_back(dp[v][1]-dp[v][0]+w); } sort(a.begin(),a.end()); for(int i=1;i<a.size();i++){ a[i]+=a[i-1]; } dp[u][0]=dp[u][1]=sum; int deg=adj[u].size(); if(deg>k){ dp[u][0]+=a[deg-k-1]; } if(deg>k+1){ dp[u][1]+=a[deg-k-2]; } } vector<ll> minimum_closure_costs(int _n,vector<int> _u,vector<int> _v,vector<int> _w){ n=_n; vector<ll> ans(n); for(int i=0;i<n-1;i++){ int u=_u[i],v=_v[i],w=_w[i]; adj[u].emplace_back(v,w); adj[v].emplace_back(u,w); ans[0]+=w; } for(int i=1;i<n;i++){ dfs(0,-1,i); ans[i]=dp[0][0]; } return ans; }

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

roads.cpp: In function 'void dfs(int, int, int)':
roads.cpp:23:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |  for(int i=1;i<a.size();i++){
      |              ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...