Submission #952032

# Submission time Handle Problem Language Result Execution time Memory
952032 2024-03-23T03:59:18 Z vjudge1 Museum (CEOI17_museum) C++14
0 / 100
1 ms 2396 KB
#include<bits/stdc++.h>
using namespace std;
const int N=10005;
int dp[N][N][2];
vector<pair<int,int> > g[N];
int siz[N];
int n,l,x;
void dfs(int x,int fa)
{
	//cout<<x<<"\n";
	dp[x][1][1]=dp[x][1][0]=0;
	siz[x]=1;
	if(g[x].size()==1&&g[x][0].first==fa)
	{
		return;
	}
	for(auto i:g[x])
	{
		
		int v=i.first;
		int w=i.second;
		if(v==fa) continue;
		dfs(v,x);
		for(int j=min(l,siz[x]);j>=0;j--)
		{
			for(int k=min(l-j,siz[v]);k>=0;k--)
			{
				dp[x][j+k][1]=min(dp[x][j+k][1],dp[x][j][1]+dp[v][k][1]+w*2);
				dp[x][j+k][0]=min(dp[x][j+k][0],dp[x][j][1]+dp[v][k][0]+w);
				dp[x][j+k][0]=min(dp[x][j+k][0],dp[x][j][0]+dp[v][k][1]+w*2);
			}
		}
		siz[x]+=siz[v];
	}
}
int main()
{
	freopen("museum.in","r",stdin);
	freopen("museum.out","w",stdout);
	cin>>n>>l>>x;
	for(int i=1;i<n;i++)
	{
		int u,v,w;
		cin>>u>>v>>w;
		g[u].push_back({v,w});
		g[v].push_back({u,w});
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<=n;j++) dp[i][j][0]=dp[i][j][1]=1e9;
	}
	dfs(x,0);
	cout<<min(dp[x][l][0],dp[x][l][1]);
}

Compilation message

museum.cpp: In function 'int main()':
museum.cpp:38:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |  freopen("museum.in","r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
museum.cpp:39:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |  freopen("museum.out","w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -