๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
Photo
int numConns(const vector<vector<int>>& grid) {
vector<int> cnt;
int rows = grid.size();
int cols = grid[0].size();
for (int i = 0; i < rows; ++i) {
int v = 0;
for (int j = 0; j < cols; ++j) {
if (grid[i][j] == 1) {
v++;
}
}
if (v != 0) {
cnt.push_back(v);
}
}
int conns = 0;
if (cnt.size() >= 2) {
for (size_t i = 0; i < cnt.size() - 1; ++i) {
conns += cnt[i] * cnt[i + 1];
}
}
return conns;
}
//Grid climing โ
vector<int> cnt;
int rows = grid.size();
int cols = grid[0].size();
for (int i = 0; i < rows; ++i) {
int v = 0;
for (int j = 0; j < cols; ++j) {
if (grid[i][j] == 1) {
v++;
}
}
if (v != 0) {
cnt.push_back(v);
}
}
int conns = 0;
if (cnt.size() >= 2) {
for (size_t i = 0; i < cnt.size() - 1; ++i) {
conns += cnt[i] * cnt[i + 1];
}
}
return conns;
}
//Grid climing โ
๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
Photo
#include <bits/stdc++.h>
using namespace std;
long solve(vector<vector<int>>& grid) {
long long prev = 0;
long long connections = 0;
for (vector<int>& row : grid) {
int sum = 0;
for (int n : row) {
sum += n;
}
if (sum > 0) {
connections += prev * sum;
prev = sum;
}
}
return connections;
}
Grid climbing โ
๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
Photo
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll solve(ll n, vector<vector<ll>>& flights, ll src, ll dst, ll k)
{
vector<pair<ll,ll>> adj[n];
for(auto it : flights){
adj[it[0]].push_back({it[1],it[2]});
}
queue<pair<ll,pair<ll,ll>>>q;
q.push({0,{src,0}});
vector<ll>dist(n,1e9);
dist[src]=0;
while(!q.empty()){
auto it=q.front();
q.pop();
ll stops=it.first;
ll node=it.second.first;
ll wt=it.second.second;
if(stops>k)continue;
for(auto iter:adj[node]){
ll adjnode=iter.first;
ll dis=iter.second;
if(wt+dis<dist[adjnode]&&stops<=k){
dist[adjnode]=wt+dis;
q.push({stops+1,{adjnode,wt+dis}});
}
}
}
if(dist[dst]==1e9)return -1;
return dist[dst];
}
signed main()
{
ll n,src,des,k,m; cin>>n>>src>>des>>k>>m;
vector<vector<ll>>a(m,vector<ll>(3));
for(ll i=0;i<m;i++)
{
ll x,y,w; cin>>x>>y>>w;
a[i]={x,y,w};
}
cout <<solve(n,a,src,des,k)<<endl;
return 0;
}
Trip planner โ
#define ll long long
using namespace std;
ll solve(ll n, vector<vector<ll>>& flights, ll src, ll dst, ll k)
{
vector<pair<ll,ll>> adj[n];
for(auto it : flights){
adj[it[0]].push_back({it[1],it[2]});
}
queue<pair<ll,pair<ll,ll>>>q;
q.push({0,{src,0}});
vector<ll>dist(n,1e9);
dist[src]=0;
while(!q.empty()){
auto it=q.front();
q.pop();
ll stops=it.first;
ll node=it.second.first;
ll wt=it.second.second;
if(stops>k)continue;
for(auto iter:adj[node]){
ll adjnode=iter.first;
ll dis=iter.second;
if(wt+dis<dist[adjnode]&&stops<=k){
dist[adjnode]=wt+dis;
q.push({stops+1,{adjnode,wt+dis}});
}
}
}
if(dist[dst]==1e9)return -1;
return dist[dst];
}
signed main()
{
ll n,src,des,k,m; cin>>n>>src>>des>>k>>m;
vector<vector<ll>>a(m,vector<ll>(3));
for(ll i=0;i<m;i++)
{
ll x,y,w; cin>>x>>y>>w;
a[i]={x,y,w};
}
cout <<solve(n,a,src,des,k)<<endl;
return 0;
}
Trip planner โ
๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
Photo
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = LLONG_MAX;
vector<ll> dijkstra(int n, int src, const vector<vector<pair<int, int>>>& adj) {
vector<ll> dist(n, INF);
dist[src] = 0;
priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<>> pq;
pq.push({0, src});
while (!pq.empty()) {
auto [d, u] = pq.top();
pq.pop();
if (d > dist[u]) continue;
for (auto [v, cost] : adj[u]) {
if (dist[u] + cost < dist[v]) {
dist[v] = dist[u] + cost;
pq.push({dist[v], v});
}
}
}
return dist;
}
vector<vector<ll>> shortest(int nodes, const vector<int>& deliveries, const vector<vector<pair<int, int>>>& adj) {
int k = deliveries.size();
vector<vector<ll>> dist(k, vector<ll>(nodes));
for (int i = 0; i < k; ++i) {
dist[i] = dijkstra(nodes, deliveries[i], adj);
}
return dist;
}
ll minTime(int nodes, int k, const vector<ll>& startDist, const vector<vector<ll>>& dist, const vector<int>& deliveries) {
vector<vector<ll>> dp(1 << k, vector<ll>(k, INF));
for (int i = 0; i < k; ++i) {
dp[1 << i][i] = startDist[deliveries[i]];
}
for (int mask = 0; mask < (1 << k); ++mask) {
for (int i = 0; i < k; ++i) {
if (mask & (1 << i)) {
for (int j = 0; j < k; ++j) {
if (!(mask & (1 << j))) {
dp[mask | (1 << j)][j] = min(dp[mask | (1 << j)][j], dp[mask][i] + dist[i][deliveries[j]]);
}
}
}
}
}
ll minTime = INF;
for (int i = 0; i < k; ++i) {
minTime = min(minTime, dp[(1 << k) - 1][i] + dist[i][0]);
}
return minTime;
}
int main() {
int n, e, c;
cin >> n >> e;
vector<int> from(e), to(e), cost(e);
for (int i = 0; i < e; ++i) {
cin >> from[i] >> to[i] >> cost[i];
}
cin >> c;
vector<int> deliveries(c);
for (int i = 0; i < c; ++i) {
cin >> deliveries[i];
}
vector<vector<pair<int, int>>> adj(n);
for (int i = 0; i < e; ++i) {
adj[from[i]].emplace_back(to[i], cost[i]);
adj[to[i]].emplace_back(from[i], cost[i]);
}
vector<ll> start = dijkstra(n, 0, adj);
vector<vector<ll>> dist = shortest(n, deliveries, adj);
ll mini = minTime(n ,c, start, dist, deliveries);
cout << mini << endl;
return 0;
}
//optimising deliveryโ
๐1
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
Techdevise is hiring for WordPress developer
2024/2023/2022 passouts eligible
Apply : https://www.linkedin.com/jobs/view/3991268851
2024/2023/2022 passouts eligible
Apply : https://www.linkedin.com/jobs/view/3991268851
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
Prodian Infotech Pvt Ltd
Job highlights
Immediate Requirement for Freshers. Requirement: Full-Stack Developer. Job Location: Chennai (Work from office only). Notice Period: Immediate joiner.
of Positions: 10. Pass-out Year: 2023 & 2024 (No backlogs). Education: B Tech / BE/BCA / BSc - CSE,ECE,IT,EEE.
Apply link : https://www.naukri.com/job-listings-hiring-freshers-full-stack-prodian-infotech-pvt-ltd-chennai-0-to-1-years-040724005342
Job highlights
Immediate Requirement for Freshers. Requirement: Full-Stack Developer. Job Location: Chennai (Work from office only). Notice Period: Immediate joiner.
of Positions: 10. Pass-out Year: 2023 & 2024 (No backlogs). Education: B Tech / BE/BCA / BSc - CSE,ECE,IT,EEE.
Apply link : https://www.naukri.com/job-listings-hiring-freshers-full-stack-prodian-infotech-pvt-ltd-chennai-0-to-1-years-040724005342
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
LinkedIn Premium at a heavy discount for a 6-month subscription!
Aโcโtโuโaโlโ Pโrโiโcโeโ:โ 8โ5โ2โ0โ IโNโRโ
Discounted Price: 850 INR
If you want pls below person on telegram: @suresh053
Person is totally trusted, no issue in that.
P.S: Will delete in sometime bcoz he have very limited number.
Aโcโtโuโaโlโ Pโrโiโcโeโ:โ 8โ5โ2โ0โ IโNโRโ
Discounted Price: 850 INR
If you want pls below person on telegram: @suresh053
Person is totally trusted, no issue in that.
P.S: Will delete in sometime bcoz he have very limited number.
๐1
๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
Photo
def dfs(node, par, depth, graph, signal_speed):
global cnt
if depth % signal_speed == 0 and depth != 0:
cnt += 1
for neighbor, weight in graph[node]:
if neighbor == par:
continue
dfs(neighbor, node, depth + weight, graph, signal_speed)
def getNumPairs(server_nodes, server_from, server_to, server_weight, signal_speed):
graph = {}
for i in range(server_nodes - 1):
if server_from[i] not in graph:
graph[server_from[i]] = []
if server_to[i] not in graph:
graph[server_to[i]] = []
graph[server_from[i]].append((server_to[i], server_weight[i]))
graph[server_to[i]].append((server_from[i], server_weight[i]))
result = []
for i in range(1, server_nodes + 1):
global cnt
cnt = 0
dfs(i, i, 0, graph, signal_speed)
result.append(cnt * (cnt - 1))
return result
Oracle โ
๐1
Product of the maximum and minimum in a dataset โ
long long result = 0;
// Helper function to calculate
// the maximum path sum using DFS
long long findMaximumPathSum(int currentNode,
int previousNode,
const vector<vector<int>> &adj,
const vector<int> &A)
{
// Nodes to which currentNode is
// connected to
const vector<int> &v = adj[currentNode];
int maximumBranchSum1 = 0;
int maximumBranchSum2 = 0;
for (auto vtx : v) {
// checking whether the branch is
// visited already
if (vtx == previousNode) {
continue;
}
long long bs = findMaximumPathSum(vtx, currentNode,
adj, A);
// Storing the maximum of value of
// branch path sums
// maximumBranchSum1 will store the
// maximum value
// maximumBranchSum2 will store the
// 2nd most maximum value
if (bs >= maximumBranchSum1) {
maximumBranchSum2 = maximumBranchSum1;
maximumBranchSum1 = bs;
}
else {
maximumBranchSum2
= max(maximumBranchSum2, bs);
}
}
result = max(result,
A[currentNode] + maximumBranchSum1
+ maximumBranchSum2);
// updating the value of current value
// with maximum path sum including
// currentNode
return A[currentNode] + maximumBranchSum1;
}
long long bestSumAnyTreePath(vector<int>& parents, vector<int>& values) {
int n = parents.size();
vector<vector<int>> mp(n);
for (int i = 0; i < n; i++) {
if (parents[i] != -1) {
mp[parents[i]].push_back(i);
}
}
result = 0;
findMaximumSumPath(0, -1, mp, values);
return result;
}
Best sum many treepath โ
Oracle
๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
Photo
vector<long> bitwiseEquations(vector<long> a, vector<long> b)
{
// long long x = 0, y = 0;
int n = a.size();
vector<long> ans(n);
for (int i = 0; i < n; i++)
{
if (a[i] < b[i])
{
ans[i] = 0;
continue;
}
long x = 0, y = 0;
long diff = a[i] - b[i];
diff /= 2;
// cout << diff << endl;
for (int j = 0; j < 64; j++)
{
if (b[i] & (1 << j))
{
if ((diff & (1 << j)) == 0)
{
// x |= (1 << j);
y |= (1 << j);
}
else
{
x = 0, y = 0;
break;
}
}
else
{
if ((diff & (1 << j)))
{
x |= (1 << j);
y |= (1 << j);
}
}
}
ans[i] = 2 * x + 3 * y;
}
return ans;
}
The bitwise Equation โ
{
// long long x = 0, y = 0;
int n = a.size();
vector<long> ans(n);
for (int i = 0; i < n; i++)
{
if (a[i] < b[i])
{
ans[i] = 0;
continue;
}
long x = 0, y = 0;
long diff = a[i] - b[i];
diff /= 2;
// cout << diff << endl;
for (int j = 0; j < 64; j++)
{
if (b[i] & (1 << j))
{
if ((diff & (1 << j)) == 0)
{
// x |= (1 << j);
y |= (1 << j);
}
else
{
x = 0, y = 0;
break;
}
}
else
{
if ((diff & (1 << j)))
{
x |= (1 << j);
y |= (1 << j);
}
}
}
ans[i] = 2 * x + 3 * y;
}
return ans;
}
The bitwise Equation โ