Coding | EXAMS | IBM ACCENTURE | VIRTUSA | IBM | AMAZON | TCS | EPAM | WILEY EDGE | TECH MAHINDRA | JPMORGAN | HCL | WIPRO
3.37K subscribers
1.13K photos
3 videos
17 files
373 links
Main channel https://t.me/Coding_000
Contact Admin 👉 @ILOVEU_143 for booking your exam slots
Web- https://coding000.github.io/Projects/
💯% clearance in any placement exams
OffCampus -https://t.me/Offcampus_000
Discussion- https://t.me/exams_discussion
Download Telegram
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

const int INF = 1e9;

struct Node {
    int value, dist;
    Node(int v, int d) : value(v), dist(d) {}
};

int main() {
    int n, m;
    cin >> n >> m;

    vector<int> A(n);
    vector<vector<int>> graph(n, vector<int>());
    vector<vector<int>> dist(n, vector<int>(n, INF));

    for (int i = 0; i < n; ++i) {
        cin >> A[i];
    }

    for (int i = 0; i < m; ++i) {
        int x, y;
        cin >> x >> y;
        --x; --y; // Convert to 0-based indexing
        graph[x].push_back(y);
        graph[y].push_back(x);
        dist[x][y] = dist[y][x] = 1;
    }

    // Floyd-Warshall algorithm to calculate shortest distances
    for (int k = 0; k < n; ++k) {
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }

    priority_queue<Node, vector<Node>, greater<Node>> pq;

    for (int i = 0; i < n; ++i) {
        if (A[i] > 0) {
            pq.push(Node(i, 0));
        }
    }

    long long cost = 0;

    while (!pq.empty()) {
        Node node = pq.top();
        pq.pop();

        int u = node.value;
        int d = node.dist;

        if (A[u] > 0) {
            cost += d * A[u];
            A[u] = 0;

            for (int v : graph[u]) {
                if (A[v] > 0) {
                    pq.push(Node(v, d + 1));
                }
            }
        }
    }

    for (int i = 0; i < n; ++i) {
        if (A[i] > 0) {
            cout << -n << endl;
            return 0;
        }
    }

    cout << cost << endl;

    return 0;
}

Tree=0

All pass Share @coding_000❤️

More Share More Solutions❤️👨‍💻
🔥2🥰1
int solve(vector<int>& arr)
{  
    if(arr.size()==1)
    {
        if(arr[0]==0) return 0;
        else return 1;
    } coding_000
    int used = 0;
    int start = 0;
    int n = arr.size();
    int result = 0;
    for (int i = 0; i < n; i++)
    {
        while ((used&arr[i])!=0)
        {
            used ^= arr[start];
            start++;
        }
        used |= arr[i];
        if (start < i)
            result+=i - start + 1;
    }

    return 2*result;
}
// Count subsets

Share @coding_000❤️
🔥3
int dp[603];
int mex(vector<int>&v, int i, int j){
     set<int>st;
     for(int ind = i;ind <= j;ind++) st.insert(v[ind]);
     int ans = 1;
     for(auto pr : st){
          if(pr == ans) ans++;
     }
     return ans;
}

int love(vector<int>& arr, int ind, int k){
    
    int n = arr.size();
    if(k == 1) return mex(arr, ind, n - 1);
                                           
    if(dp[ind] != -1)  return dp[ind];

    int maxi = INT_MIN;

    for(int i = ind;i <= (n - k);i++){
       int ans = mex(arr, ind, i) + helper(arr, i + 1, k - 1);
       maxi = max(maxi, ans);
    }

    return dp[ind] = maxi;
}


int solve(int N, int K, vector<int>A){

     memset(dp, -1, sizeof(dp));
    return love(A, 0 , K);

}
// Max Strikes again

https://t.me/coding_000 ❤️
🔥3
Guys share the screenshot in large groups and Share with your friends 🔥 @Coding_000 ❤️

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❤️
👍4
He share our channel to Friends Now I am giving Free solution

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❤️👨‍💻
👍3
Dm @ILOVEU_143


For Coding Help or Any Exam Help
😄


💯 Clearance

Check the previous proofs 👆👆

Share @Coding_000❤️
1👍1🔥1
Dm @ILOVEU_143


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
👍3