?
# | Author | Problem | Lang | Verdict | Time | Memory | Sent | Judged | |
---|---|---|---|---|---|---|---|---|---|
89096473 |
Practice: PremKapshi1234 |
1399E1 - 19 | C++14 (GCC 6-32) | Wrong answer on test 2 | 30 ms | 3780 KB | 2020-08-06 10:22:20 | 2020-08-06 10:22:20 |
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <cmath> #include <stack> #include <set> #include <map> #include <unordered_map> #include <queue> using namespace std; #define Fio \ ios_base::sync_with_stdio(false); \ cin.tie(nullptr); \ cout.tie(nullptr) #define f(i, n) for (long long int i = 0; i < n; i++) #define ll long long int #define fo(i, a, b) for (long long int i = a; i <= b; i++) #define w(t) \ int t; \ cin >> t; \ while (t--) #define vi vector<int> #define vl vector<long long int> #define vvi vector<vector<int>> #define vvl vector<vector<long long int>> #define mii map<int, int> #define umii unordered_map<int, int> #define newl cout<<"\n" #define pb push_back #define mp make_pair #define fi first #define se second const ll inf = 1e9 + 7; const ll modc = 998244353; #define MAX 100002 ll sum = 0; int dfs(ll node,ll prev,vector<vector<pair<ll,ll>>> &G, vi &vis,priority_queue<pair<ll,ll>> &Q){ int ans = 0; for(auto x: G[node]){ if(x.fi==prev)continue; int tmp = dfs(x.fi,node,G,vis,Q); Q.push(mp(tmp,x.se)); sum += tmp*x.se; ans += tmp; } if(!ans)ans = 1; return ans; } void solve(){ ll n,S; cin>>n>>S; vector<vector<pair<ll,ll>>> G(n+1); f(i,n-1){ ll u,v,w; cin>>u>>v>>w; G[u].pb(mp(v,w)); G[v].pb(mp(u,w)); } vi vis(n+1,0); priority_queue<pair<ll,ll>>Q; dfs(1,0,G,vis,Q); int mov = 0; while(sum>S){ mov++; pair<ll,ll> A = Q.top(); Q.pop(); sum -= A.fi*A.se; A.se=A.se/2; if(A.se){ sum += A.se*A.fi; Q.push(mp(A.fi,A.se)); } } cout<<mov; newl; sum = 0; } int main(){ Fio; w(t){ solve(); } return 0; }
?
?
?
?