Guys share the screenshot in large groups and Share with your friends ✅🔥 @Coding_000 ❤️
I don't see anyone sharing 🥲
I don't see anyone sharing 🥲
❤4
#include<bits/stdc++.h>
using namespace std;
const int N=500005;
typedef long long ll;
int T,n,k,t,h[N];
ll dp[N][2];
struct edge{
int ver,net;
ll val;
}f[N*2];
void add(int x,int y,int z){
f[++t].net=h[x];
h[x]=t,f[t].ver=y;
f[t].val=z;
}
void dfs(int x,int fa){
dp[x][0]=dp[x][1]=0;
priority_queue<ll> q;
for(int i=h[x];i;i=f[i].net){
int y=f[i].ver;
if(y==fa) continue;
dfs(y,x);
dp[x][0]+=dp[y][0];
q.push(dp[y][1]+f[i].val-dp[y][0]);
}
dp[x][1]=dp[x][0];
int p=k;
while(p--&&q.size()&&q.top()>0){
if(p) dp[x][1]+=q.top();
dp[x][0]+=q.top();
q.pop();
}
}
int main(){
scanf("%d",&T);
while(T--){
int x,y,z;t=0;
scanf("%d%d",&n,&k);
for(int i=1;i<n;++i){
scanf("%d%d%d",&x,&y,&z);
add(x,y,z),add(y,x,z);
}
dfs(1,0);
printf("%lld\n",dp[1][0]);
for(int i=1;i<=n;++i) h[i]=0,dp[i][0]=dp[i][1]=0;
}
return 0;
}
// Good edges✅
Share @coding_000❤️
using namespace std;
const int N=500005;
typedef long long ll;
int T,n,k,t,h[N];
ll dp[N][2];
struct edge{
int ver,net;
ll val;
}f[N*2];
void add(int x,int y,int z){
f[++t].net=h[x];
h[x]=t,f[t].ver=y;
f[t].val=z;
}
void dfs(int x,int fa){
dp[x][0]=dp[x][1]=0;
priority_queue<ll> q;
for(int i=h[x];i;i=f[i].net){
int y=f[i].ver;
if(y==fa) continue;
dfs(y,x);
dp[x][0]+=dp[y][0];
q.push(dp[y][1]+f[i].val-dp[y][0]);
}
dp[x][1]=dp[x][0];
int p=k;
while(p--&&q.size()&&q.top()>0){
if(p) dp[x][1]+=q.top();
dp[x][0]+=q.top();
q.pop();
}
}
int main(){
scanf("%d",&T);
while(T--){
int x,y,z;t=0;
scanf("%d%d",&n,&k);
for(int i=1;i<n;++i){
scanf("%d%d%d",&x,&y,&z);
add(x,y,z),add(y,x,z);
}
dfs(1,0);
printf("%lld\n",dp[1][0]);
for(int i=1;i<=n;++i) h[i]=0,dp[i][0]=dp[i][1]=0;
}
return 0;
}
// Good edges✅
Share @coding_000❤️
👍4
He share our channel to Friends Now I am giving Free solution
All test cases pass ✅
Share @Coding_000❤️
All test cases pass ✅
Share @Coding_000❤️
❤2👍1🥰1
DM @ILOVEU_143 ❤️✅
Send me our channel screenshot
Send ur questions i will send solutions
Dm Me Fast @ILOVEU_143❤️✅
Share @Coding_000❤️👨💻
Send me our channel screenshot
Send ur questions i will send solutions
Dm Me Fast @ILOVEU_143❤️✅
Share @Coding_000❤️👨💻
👍3
Dm @ILOVEU_143✅
For Coding Help or Any Exam Help 😄
💯 Clearance ✅
Check the previous proofs 👆👆
Share @Coding_000❤️
For Coding Help or Any Exam Help 😄
💯 Clearance ✅
Check the previous proofs 👆👆
Share @Coding_000❤️
❤1👍1🔥1
🔥5
Dm @ILOVEU_143✅
For Coding Help or Any Exam Help 😄
💯 Clearance ✅
Check the previous proofs 👆👆
Share @Coding_000❤️
For Coding Help or Any Exam Help 😄
💯 Clearance ✅
Check the previous proofs 👆👆
Share @Coding_000❤️
👍3
TECH Mahindra Exam
Round 2
Help available.👨💻
100% Clearance GUARANTEE.✅
Check our past Results. 👇👇
https://t.me/Coding_000/5567?single
https://t.me/Coding_000/5563?single
Contact @ILOVEU_143 ✅
Round 2
Help available.👨💻
100% Clearance GUARANTEE.✅
Check our past Results. 👇👇
https://t.me/Coding_000/5567?single
https://t.me/Coding_000/5563?single
Contact @ILOVEU_143 ✅
👍3
Say this with me:
I can make my dream life, career, and money real.
I have a plan, and it's happening now.
I'll achieve it, no matter what.
Never Give Up 😊
@OFFCAMPUS_000 ❤️
I can make my dream life, career, and money real.
I have a plan, and it's happening now.
I'll achieve it, no matter what.
Never Give Up 😊
@OFFCAMPUS_000 ❤️
❤2🔥2🥰1
Dm @ILOVEU_143✅
For Coding Help or Any Exam Help 😄
💯 Clearance ✅
Check the previous proofs 👆👆
Share @Coding_000❤️
For Coding Help or Any Exam Help 😄
💯 Clearance ✅
Check the previous proofs 👆👆
Share @Coding_000❤️
👍2
SELECT
id,
title,
s.quantity AS total_stock,
r.quantity AS total_returns
FROM
products p
LEFT JOIN stocks s
ON p.id = s.product_id
LEFT JOIN ( SELECT product_id, COUNT( * ) AS quantity FROM returns WHERE MONTHNAME( dt ) = 'July' GROUP BY product_id ) r
ON p.id = r.product_id
ORDER BY
id
E-commerce sql
id,
title,
s.quantity AS total_stock,
r.quantity AS total_returns
FROM
products p
LEFT JOIN stocks s
ON p.id = s.product_id
LEFT JOIN ( SELECT product_id, COUNT( * ) AS quantity FROM returns WHERE MONTHNAME( dt ) = 'July' GROUP BY product_id ) r
ON p.id = r.product_id
ORDER BY
id
E-commerce sql
👍2