#include "closing.h"
#include <vector>
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
const long long INF = 1e18+1;
typedef long long ll;
const ll MOD = 1e9+7;
#define F first
#define P pair
#define S second
#define pb push_back
#define all(v) v.begin(), v.end()
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
void file() {
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
}
vector<P<int,ll>>adj[(int)3001];
bool b[(int)3001];
ll d1[(int)3001];
ll d2[(int)3001];
void dfs1(int n,int p,int y) {
if (n==y) {
b[n]=true;
return;
}
for (auto [u,w]:adj[n]) {
if (u==p)continue;
dfs1(u,n,y);
b[n]|=b[u];
}
}
void dfs2(int n,int p) {
for (auto [u,w]:adj[n]) {
if (u==p)continue;
d1[u]=d1[n]+w;
dfs2(u,n);
}
}
void dfs3(int n,int p) {
for (auto [u,w]:adj[n]) {
if (u==p)continue;
d2[u]=d2[n]+w;
dfs3(u,n);
}
}
int max_score(int N, int X, int Y, long long K,
std::vector<int> U, std::vector<int> V, std::vector<int> W)
{
for (int i=0;i<=N;i++) {
adj[i].clear();
b[i]=false;
}
d1[X]=0;d2[Y]=0;
for (int i=0;i<N-1;i++) {
adj[U[i]].pb({V[i],W[i]});
adj[V[i]].pb({U[i],W[i]});
}
dfs1(X,-1,Y);
dfs2(X,-1);
dfs3(Y,-1);
for (int i=0;i<N;i++) {
if (d1[i]>d2[i])swap(d1[i],d2[i]);
}
ll dp1[2*N+1],dp2[2*N+1];
for (int i=0;i<2*N+1;i++) {
dp1[i]=INF;dp2[i]=INF;
}
dp1[0]=0LL,dp2[0]=0LL;
for (int i=0;i<N;i++) {
for (int j=2*N;j>=1;j--) {
dp1[j]=min(dp1[j],dp1[j-1]+d1[i]);
if (b[i]) {
dp2[j]=min(dp2[j],dp2[j-1]+d2[i]-d1[i]);
}
else {
dp2[j]=min(dp2[j],dp2[j-1]+d1[i]);
if (j>=2) {
dp2[j]=min(dp2[j],dp2[j-2]+d2[i]);
}
}
}
}
int ans=0;
int c=0;ll cst=0;
for (int i=0;i<N;i++) {
if (b[i]) {
c++;
cst+=d1[i];
}
}
for (int i=1;i<=2*N;i++) {
if (dp1[i]<=K) {
ans=max(ans,i);
}
if (dp2[i]+cst<=K) {
ans=max(ans,c+i);
}
}
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
closing.cpp: In function 'void file()':
closing.cpp:19:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
19 | freopen("input.txt","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
closing.cpp:20:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
20 | freopen("output.txt","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |