๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.62K subscribers
5.59K photos
3 videos
95 files
10.2K links
๐ŸšฉMain Group - @SuperExams
๐Ÿ“Job Updates - @FresherEarth

๐Ÿ”ฐAuthentic Coding Solutions(with Outputs)
โš ๏ธDaily Job Updates
โš ๏ธHackathon Updates & Solutions

Buy ads: https://telega.io/c/cs_algo
Download Telegram
from collections import deque

def bfs(graph, source, dest):
    queue = deque([(source, 0)])
    while queue:
        node, dist = queue.popleft()
        if node == dest:
            return dist
        for neighbor in graph[node]:
            if neighbor != node:
                queue.append((neighbor, dist + 1))
    return -1

def solve():
    t = int(input())
    for _ in range(t):
        n = int(input())
        a, b, c = map(int, input().split())
        graph = {}
        for _ in range(n - 1):
            x, y = map(int, input().split())
            if x not in graph:
                graph[x] = []
            if y not in graph:
                graph[y] = []
            graph[x].append(y)
            graph[y].append(x)

        atoc = bfs(graph, a, c)
        btoc = bfs(graph, b, c)
        atob = bfs(graph, a, b)

        if atoc < btoc:
            print("A")
        elif atob < atoc:
            print("B")
        elif btoc < atoc:
            print("C")
        else:
            print("DRAW")

if name == "main":
    solve()


Three Person โœ… ICPC
#include<bits/stdc++.h>
using namespace std;

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

    vector<vector<int>> cust;
    for(int i = 0; i < n; i++) {
        int q, p;
        cin >> q >> p;
        cust.push_back({p, q});
    }

    vector<vector<int>> rice;
    for(int i = 0; i < m; i++) {
        int q, p;
        cin >> q >> p;
        rice.push_back({p, q});
    }

    sort(cust.begin(), cust.end());
    sort(rice.begin(), rice.end());

    vector<int> x(m, 0);
    int ans = 0;

    for(int i = 0; i < n; i++) {
        int quantity = -1;
        int index = -1;
        for(int j = 0; j < m; j++) {
            if (!x[j]) {
                if (rice[j][0] > cust[i][0]) break;

                if (rice[j][1] > cust[i][1]) {
                    if (quantity == -1) {
                        quantity = rice[j][1];
                        index = j;
                    } else {
                        if (quantity > rice[j][1]) {
                            index = j;
                            quantity = rice[j][1];
                        }
                    }
                }
            }
        }

        if (index != -1) {
            x[index] = 1;
            ans++;
        }
    }

    cout << ans;
}

Super market Codevita โœ…
#include <stdio.h>

int cd=0,ca=0;
void bd(int array[], int n) {
  for (int step = 0; step < n - 1; ++step) {
    for (int i = 0; i < n - step - 1; ++i) {
      if (array[i] < array[i + 1]) {
        int temp = array[i];
        array[i] = array[i + 1];
        array[i + 1] = temp;
        cd++;
      }
    }
  }
}

void ba(int array[], int n) {
  for (int step = 0; step < n - 1; ++step) {
    for (int i = 0; i < n - step - 1; ++i) {
      if (array[i] > array[i + 1]) {
        int temp = array[i];
        array[i] = array[i + 1];
        array[i + 1] = temp;
        ca++;
      }
    }
  }
}

int main() {
    int n;
    scanf("%d",&n);
    int da[n],dd[n];
    for(int i=0;i<n;i++){
        scanf("%d",&da[i]);
        dd[i]=da[i];
    }
    ba(dd, n);
    bd(da, n);
    if(cd>ca)
      printf("%d",ca);
    else
      printf("%d",cd);
}

Best Bubble Codevita โœ…
๐Ÿ‘2
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include<bits/stdc++.h>
#define fastread()  (ios_base:: sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL));
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define test(x)  int x; cin>>x; while(x--)
#define int long long int
#define print(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" ";
#define input(a,n) for(int i=0;i<n;i++) cin>>a[i];
int M= 1e9+7;
#define endl "\n"
int ncr(int n,int r){ int res=1; if(r>n-r)r=n-r; for(int i=0;i<r;i++) {  res*=n-i;  res/=i+1; } return res; }
//int f(int n)  {if (n >= M) return 0;int result = 1; for (int i = 1; i <= n; i++) result = (result * i) % M;return result;}

using namespace std;

int dx[] = { 0,1,0,-1, -1, 1, 1, -1};
int dy[] = {-1,0,1,0,   1, 1, -1, -1};

int dfs(int node, vector<vector<int>> &adj, vector<bool> &vis, vector<bool> &corrupt)
{
    queue<int> q;
    int mini =  INT_MAX;
    q.push(node);
 
    while(!q.empty())
    {
        int x = q.front();
        q.pop();
        if(x !=node && !corrupt[x])
            mini = min(mini, x);
        for(auto it : adj[x])
        {
          if(!vis[it])
             {
                q.push(it);
                vis[it] = true;
            }
        }
    }
    return mini == INT_MAX? -1: mini;

}
int solve()
{
    int nodes, edges;
    cin >> nodes >> edges;
    int n =  nodes;
    int temp1;
    cin >>  temp1;
    vector<bool> vis(n + 1, false);
    vector<vector<int>> adj(n + 1);
    for(int i = 0;i < edges;i++)
    {
        int p, q;
        cin >> p >> q;
        adj[p].push_back(q);
        adj[q].push_back(p);

    }


    int q;
    cin >> q;
    int temp;
    cin >> temp;

    vector<int> ans;
    vector<bool> corrupt(n + 1, false);
    while(q--)
    {
        int x, y;
        cin >> x >> y;

        if(x  ==  1)
        {
           vector<bool> vis(n + 1, false);
           int mini = y;
           if(corrupt[y])
             {
                mini =  dfs(y, adj, vis, corrupt);
            }
         
           ans.push_back(mini);
        }

        else
            corrupt[y] = true;
    }

    for(int i = 0; i < ans.size();i++)
        cout << ans[i] << endl;
    return 0;
}



signed main() {
    solve();
    return 0;
}

UBSโœ…
Dead Pod Recovery