# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
502755 | ctd6969 | Džumbus (COCI19_dzumbus) | C++17 | 27 ms | 2900 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double db;
const ll mod = 1e9 + 7; // 998244353
const ll inf = 1e18;
using pl = pair<ll,ll>;
using pi = pair<int,int>;
using vi = vector<int>;
using vl = vector<ll>;
using vpi = vector<pair<int,int>>;
using vpl = vector<pair<ll,ll>>;
#define mp make_pair
#define f first
#define s second
#define foru(i,a,b) for(ll i = a ; i <= b;i++)
#define ford(i,a,b) for(ll i = a ; i >= b;i--)
#define psh push
#define em emplace
#define eb emplace_back
#define pb push_back
#define all(x) (x).begin(),(x).end()
ll n , m;
ll drink[1002];
vl E[1002];
vl dp[1002];// Gọi dp[i][j] là số dzumbus nhỏ nhất để có chính xác j người uống trong cây con gốc i
vl total_min(vl a, vl b){
vl temp(a.size() + b.size() - 1,inf);
foru(i,0,a.size() - 1){
foru(j,0,b.size() - 1){
temp[i + j] = min(temp[i + j],a[i] + b[j]);
}
}
return temp;
}
void process(ll g,ll before){
dp[g] = {0,drink[g]};
for(ll c : E[g]){
if(c == before) continue;
process(c,g);
dp[g] = total_min(dp[g],dp[c]);
}
}
int main(void){
// #ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// #endif //ONLINE_JUDGE
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin >> n >> m;
foru(i,1,n) cin >> drink[i];
ll a , b , q;
foru(i,1,m){
cin >> a >> b;
E[a].eb(b);
E[b].eb(a);
}
process(1,-1);
cin >> q;
while(q--){
cin >> a;
ford(j,n,0){
if(dp[1][j] <= a){
if( j == 1) cout << 0 <<'\n';
else cout << j <<'\n';
break;
}
}
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |