Submission #493658

# Submission time Handle Problem Language Result Execution time Memory
493658 2021-12-12T14:06:46 Z inksamurai Džumbus (COCI19_dzumbus) C++17
50 / 110
204 ms 56524 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define sz(a) (ll)a.size()
#define all(a) a.begin(),a.end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define crep(i,x,n) for(ll i=x;i<n;i++)
#define drep(i,n) for(ll i=n-1;i>=0;i--)
#define vec(...) vector<__VA_ARGS__>
#define _3dDwnkq ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
using pii=pair<ll,ll>;
using vi=vector<ll>;

const ll inf=1e12;

int main(){
_3dDwnkq;
	ll n,m;
	cin>>n>>m;
	vi a(n);
	rep(i,n){
		cin>>a[i];
	}
	vec(vi) adj(n);
	rep(i,m){
		ll u,v;
		cin>>u>>v;
		u--,v--;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	vi chs(n,0);
	vi usd(n,0);
	auto dfs=[&](auto self,ll v)->void{
		chs[v]=1;
		usd[v]=1;
		for(auto u : adj[v]){
			if(!usd[u]){
				self(self,u);
				chs[v]+=chs[u];
			}
		}
	};
	rep(v,n){
		if(!usd[v]){
			dfs(dfs,v);
		}
	}
	usd=vi(n,0);
	vec(vec(vi)) dp(n+1,vec(vi)(n+1,vi(2,1e9)));
	auto magicaldfs=[&](auto self,ll v)->void{
		usd[v]=1;
		dp[v][0][0]=0;
		ll now=1;
		for(auto u : adj[v]){
			if(!usd[u]){
				self(self,u);
				ll pnow=now;
				drep(j,pnow+1){
					drep(k,chs[u]+1){
						ll nej=j+k;
						dp[v][nej][0]=min({
							dp[v][nej][0],
							dp[v][j][0]+min(dp[u][k][1],dp[u][k][0])
						});
						if(nej+1<=n) dp[v][nej+1][1]=min({
							dp[v][nej+1][1],
							dp[v][j][1]+dp[u][k][0]+a[u],
							dp[v][j][0]+dp[u][k][1]+a[v]
						});
						if(nej+2<=n) dp[v][nej+2][1]=min({
							dp[v][nej+2][1],
							dp[v][j][0]+dp[u][k][0]+a[v]+a[u]
						});
						dp[v][nej][1]=min({
							dp[v][nej][1],
							dp[v][j][1]+min(dp[u][k][1],dp[u][k][0])
						});
					}
				}
				now+=chs[u];
			}
		}
	};
	vi fdp(n+1,inf);
	fdp[0]=0;
	ll now=0;
	rep(v,n){
		if(!usd[v]){
			magicaldfs(magicaldfs,v);
			drep(j,now+1){
				drep(nej,chs[v]+1){
					fdp[nej+j]=min(fdp[nej+j],fdp[j]+min(dp[v][nej][0],dp[v][nej][1]));
				}
			}
		}
	}
	// crep(v,2,n+1){
	// 	fdp[v]=min(fdp[v],fdp[v-1]);
	// }
	ll q;
	cin>>q;
	rep(_,q){
		ll x;
		cin>>x;
		drep(i,n+1){
			if(fdp[i]<=x){
				cout<<i<<"\n";
				break;
			}
		}
		// ll l=0,r=n+1,c=-1;
		// while(l<=r){
		// 	ll m=(l+r)>>1ll;
		// 	if(fdp[m]<=x){
		// 		c=m;
		// 		l=m+1;
		// 	}else{
		// 		r=m-1;
		// 	}
		// }
		// cout<<c<<"\n";
	}
//	
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 71 ms 55536 KB Output is correct
2 Correct 67 ms 55484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 55536 KB Output is correct
2 Correct 67 ms 55484 KB Output is correct
3 Correct 115 ms 56524 KB Output is correct
4 Correct 116 ms 56296 KB Output is correct
5 Correct 204 ms 55896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 1672 KB Output is correct
2 Incorrect 42 ms 1476 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 71 ms 55536 KB Output is correct
2 Correct 67 ms 55484 KB Output is correct
3 Correct 115 ms 56524 KB Output is correct
4 Correct 116 ms 56296 KB Output is correct
5 Correct 204 ms 55896 KB Output is correct
6 Correct 28 ms 1672 KB Output is correct
7 Incorrect 42 ms 1476 KB Output isn't correct
8 Halted 0 ms 0 KB -