제출 #1081192

#제출 시각아이디문제언어결과실행 시간메모리
1081192alexander707070도로 폐쇄 (APIO21_roads)C++14
31 / 100
2100 ms38984 KiB
#include<bits/stdc++.h> #include "roads.h" #define MAXN 100007 using namespace std; const long long inf=1e10; int n,a,b,k,sz[MAXN]; long long sum; vector<int> toadd[MAXN]; vector< pair<int,int> > v[MAXN],g[MAXN]; long long dp[MAXN][2]; int li[MAXN][2],tim; struct edges{ vector<int> s; void add(int x){ s.push_back(x); sort(s.begin(),s.end()); } void rem(int x){ for(int i=0;i<s.size();i++){ if(s[i]==x){ swap(s[i],s[s.size()-1]); s.pop_back(); break; } } sort(s.begin(),s.end()); } }bonus[MAXN]; long long ff(int x,int p,bool par){ if(li[x][par]==tim)return dp[x][par]; li[x][par]=tim; dp[x][par]=0; vector<long long> s; for(int i=0;i<v[x].size();i++){ if(v[x][i].first==p){ if(par)dp[x][par]+=v[x][i].second; continue; } s.push_back(ff(v[x][i].first,x,true)-ff(v[x][i].first,x,false)); dp[x][par]+=ff(v[x][i].first,x,false); } sort(s.begin(),s.end()); int pt=0; for(int i=0;i<sz[x]-k-par-pt or (i<int(s.size()) and s[i]<0);i++){ /*if(s.empty() or (pt<bonus[x].s.size() and bonus[x].s[pt]<s[i])){ dp[x][par]+=bonus[x].s[pt]; pt++; i--; }else{*/ dp[x][par]+=s[i]; //} } return dp[x][par]; } bool in[MAXN]; vector<int> roots; vector<long long> minimum_closure_costs(int N,vector<int> U,vector<int> V,vector<int> W){ n=N; for(int i=1;i<=n-1;i++){ a=U[i-1]; b=V[i-1]; a++; b++; bonus[a].add(W[i-1]); bonus[b].add(W[i-1]); sz[a]++; sz[b]++; v[a].push_back({b,W[i-1]}); v[b].push_back({a,W[i-1]}); sum+=W[i-1]; } for(int i=1;i<=n;i++){ toadd[sz[i]-1].push_back(i); } vector<long long> res; for(int i=n-1;i>=1;i--){ for(int f:toadd[i]){ for(pair<int,int> k:g[f]){ if(!in[k.first])continue; //v[f].push_back({k.first,k.second}); //v[k.first].push_back({f,k.second}); bonus[f].rem(k.second); bonus[k.first].rem(k.second); } in[f]=true; roots.push_back(f); } long long curr=0; tim++; k=i; for(int f:roots){ if(li[f][0]==tim)continue; curr+=ff(f,0,0); } res.push_back(curr); } res.push_back(sum); reverse(res.begin(),res.end()); return res; } /*int main(){ //vector<long long> s=minimum_closure_costs(5, {0, 0, 0, 2}, {1, 2, 3, 4}, {1, 4, 3, 2}); //vector<long long> s=minimum_closure_costs(4, {0, 2, 0}, {1, 0, 3}, {5, 10, 5}); for(long long i:s)cout<<i<<" "; return 0; }*/

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

roads.cpp: In member function 'void edges::rem(int)':
roads.cpp:27:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |         for(int i=0;i<s.size();i++){
      |                     ~^~~~~~~~~
roads.cpp: In function 'long long int ff(int, int, bool)':
roads.cpp:46:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     for(int i=0;i<v[x].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...