Submission #579748

#TimeUsernameProblemLanguageResultExecution timeMemory
579748AGEDžumbus (COCI19_dzumbus)C++14
0 / 110
357 ms45016 KiB
#include<bits/stdc++.h> #define F first #define S second #define int long long #define pb push_back using namespace std; const int N=1e6,M=2e3,mod=1e9+7; int dp[M][M][2],a[N],parr[N],son[N]; vector<int>adj[N]; int node2; bool ok(int mid,int val){ for(int j=0;j<2;j++){ if(dp[node2][mid][j]<=val) return 1; } return 0; } void dfs2(int node,int par){ for(auto x:adj[node]){ if(x==par){ parr[node]=par; continue; } son[node]=x; dfs2(x,node); } } void dfs(int node,int par){ //cout<<"#%&$%@^@#^$%^"<<endl; if(son[node]==node) return ; for(int j=0;j<=1000;j++){ dp[son[node]][j+1][1]=min(dp[son[node]][j+1][1],dp[node][j][1]+a[son[node]]); dp[son[node]][j][0]=min(dp[son[node]][j][0],dp[node][j][1]); dp[son[son[node]]][j+2][1]=min(dp[son[son[node]]][j+2][1],dp[node][j][0]+a[son[node]]+a[son[son[node]]]); dp[son[node]][j][0]=min(dp[son[node]][j][0],dp[node][j][0]); } dfs(son[node],node); } main(){ int n,m; cin>>n>>m; for(int i=1;i<=n;i++) cin>>a[i]; for(int i=0;i<m;i++){ int x,y; cin>>x>>y; adj[x].pb(y); adj[y].pb(x); } int node=1,par=0; for(int i=0;i<=1000;i++) for(int j=0;j<=1000;j++) for(int k=0;k<2;k++) dp[i][j][k]=1e18; for(int i=1;i<=n;i++) if(adj[i].size()==1) node=i; for(int i=1;i<=n;i++) if(adj[i].size()==1&&node!=i) node2=i; dfs2(node,0); son[node2]=node2; dp[node][0][0]=0; dp[son[node]][1][1]=a[node]+a[son[node]]; dfs(node,0); int q; cin>>q; for(int i=999;i>=0;i--) for(int j=0;j<2;j++) dp[node2][i][j]=min(dp[node2][i][j],dp[node2][i+1][j]); while(q--){ int val; cin>>val; int ans=-1e18; int l=0,r=1000; while(l<r){ int okk=0; int mid=(l+r+1)/2; if(ok(mid,val)) l=mid; else r=mid-1; } cout<<l<<endl; } return 0; }

Compilation message (stderr)

dzumbus.cpp:58:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   58 | main(){
      | ^~~~
dzumbus.cpp: In function 'int main()':
dzumbus.cpp:117:17: warning: unused variable 'okk' [-Wunused-variable]
  117 |             int okk=0;
      |                 ^~~
dzumbus.cpp:113:13: warning: unused variable 'ans' [-Wunused-variable]
  113 |         int ans=-1e18;
      |             ^~~
dzumbus.cpp:77:16: warning: unused variable 'par' [-Wunused-variable]
   77 |     int node=1,par=0;
      |                ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...