이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "closing.h"
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18+1;
int max_score(int N,int X,int Y,long long K,
vector<int> U,vector<int> V,vector<int> W){
vector<vector<pair<int,long long>>> adj(N);
for(int i=0;i<N-1;i++) {
adj[U[i]].emplace_back(V[i],W[i]);
adj[V[i]].emplace_back(U[i],W[i]);
}
vector<long long> distX(N);
vector<long long> distY(N);
auto dijkastra = [&](int x) {
priority_queue<pair<long long,int>> pq;
pq.emplace(0,x);
vector<bool> visited(N);
while(!pq.empty()) {
auto [dist,idx] = pq.top();pq.pop();dist=-dist;
if(visited[idx])continue;
visited[idx]=true;
distX[idx]=dist;
for(auto[v,c]:adj[idx])if(!visited[v])pq.emplace(-dist-c,v);
}
};
dijkastra(Y);
swap(distX,distY);
dijkastra(X);
vector cost1(N+1,0ll);
vector cost2(N+1,0ll);
for(int i=0;i<N;i++) {
long long mini = min(distX[i],distY[i]);
long long maxi = max(distX[i],distY[i]);
cost1[i+1] = mini;
cost2[i+1] = maxi;
}
vector DP(N+1,vector(2*N+1,INF));
DP[0][0]=0;
for(int i=1;i<=N;i++) {
DP[i][0]=0;
DP[i][1]=min(DP[i-1][1],cost1[i]);
for(int j=2;j<=2*N;j++) {
DP[i][j]=min({DP[i-1][j],DP[i-1][j-1]+cost1[i],DP[i-1][j-2]+cost2[i]});
}
}
for(int j=2*N;j;j--)if(DP[N][j]<=K)return j;
assert(false);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |