Submission #780061

# Submission time Handle Problem Language Result Execution time Memory
780061 2023-07-12T06:21:48 Z vjudge1 Dostavljač (COCI18_dostavljac) C++17
0 / 140
303 ms 8972 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long lo; 

#define fi first
#define se second
#define endl "\n"
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo inf = 1000000000;
const lo li = 505;
const lo mod = 1000000007;

int n,m,a[li],k,flag,t,b[li],say,dist[li][li],dp[li][li];
int cev;
string s;
vector<int> v[li];
vector<pair<int,int>> vv;

inline int in(){
	int x;
	scanf("%d",&x);
	return x;
}

inline void dfs(int node,int ata){
	b[++say]=node;
	for(auto go:v[node]){
		if(go==ata)continue;
		dfs(go,node);
	}
}

inline void dfs2(int node,int ata,int dep,int start){
	dist[start][node]=dep;
	for(auto go:v[node]){
		if(go==ata)continue;
		dfs2(go,node,dep+1,start);
	}
}

int main(void){
	n=in(),m=in();
	FOR a[i]=in();
	for(int i=1;i<n;i++){
		int x=in(),y=in();
		v[x].pb(y);
		v[y].pb(x);
	}
	dfs(1,0);
	FOR dfs2(i,0,0,i);
	FOR{
		for(int j=0;j<=m;j++)dp[i][j]=-1000000000;
	}
	dp[1][0]=0;
	dp[1][1]=a[1];
	FOR{
		vv.pb({b[i],i});
	}
	sort(vv.begin(),vv.end());
	for(int go=0;go<n;go++){
		int i=vv[go].se;
		for(int j=0;j<=m;j++){
			for(int go1=0;go1<go;go1++){
				int ii=vv[go1].se;
				int at=j-dist[ii][i];
				if(at<0)continue;
				dp[i][j]=max(dp[i][j],dp[ii][at]);
				dp[i][j+1]=max(dp[i][j+1],dp[ii][at]+a[i]);
				//~ cout<<i<<" AA "<<ii<<" AA "<<at<<endl;
			}
		}
	}
	FOR{
		for(int j=0;j<=m;j++){
			cev=max(cev,dp[i][j]);
			cout<<i<<" ()() "<<j<<" ()() "<<dp[i][j]<<endl;
		}
	}
	printf("%d\n",cev);
	return 0;
}

Compilation message

dostavljac.cpp: In function 'int in()':
dostavljac.cpp:28:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |  scanf("%d",&x);
      |  ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 324 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 576 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 1172 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 1212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 43 ms 3240 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 42 ms 2908 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 173 ms 6140 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 303 ms 8972 KB Output isn't correct
2 Halted 0 ms 0 KB -