Submission #950597

#TimeUsernameProblemLanguageResultExecution timeMemory
950597NexusTwo Currencies (JOI23_currencies)C++17
10 / 100
159 ms192964 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; const ll N=2e3+9,M=2e18+9,mod=1e9+7; ll a[N],b[N],n,m,q,s,t,x,y,z; vector<ll>v[N],ed[N][N],p; void dfs(ll node,ll ca) { if(node==t) { z=1; return; } for(auto i:v[node]) if(i!=ca) { ll g=p.size(); for(auto j:ed[node][i])p.push_back(j); dfs(i,node); if(z)return; ll k=g+ed[node][i].size(); for(ll j=g;j<k;++j)p[j]=0; } } ll ans() { p.clear(); z=0; dfs(s,s); sort(p.begin(),p.end()); n=p.size(); for(ll i=0;i<n;++i) { if(p[i]<=y)y-=p[i]; else { x-=p.size()-i; break; } } if(x>=0)return x; return -1; } int main() { ios::sync_with_stdio(0); cin.tie(0);cout.tie(0); cin>>n>>m>>q; for(ll i=1;i<n;++i) { cin>>a[i]>>b[i]; v[a[i]].push_back(b[i]); v[b[i]].push_back(a[i]); } for(ll i=0;i<m;++i) { cin>>x>>y; ed[a[x]][b[x]].push_back(y); ed[b[x]][a[x]].push_back(y); } while(q--) { cin>>s>>t>>x>>y; cout<<ans()<<'\n'; } return 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...