ADD REPLY • link 15 months ago mk390270 • 50
You are given a graph G of N nodes and M edges and each edge has some time associated with it.
There is a policeman standing on each node except Node N.
All of them get a report that there is thief on Node N and the policemen start moving towards it, but all of them have been hungry for days, so they are looking to visit a few restaurants as well, before reaching the node N.
There are K restaurants present on some nodes, and each restaurant has some satisfaction. Now, a policeman will only go to a restaurant if and only if the satisfaction he receives by reaching the restaurant is greater than the time he has invested in reaching there and then going to the Node N.
Find and return the number of policemen who will have a meal at a restaurant.
Input Format:
The first argument contains an integer A, representing the number of nodes.
The second argument of input contains a 2 d matrix of size M x 3, B, where Node B[i][0] and Node B[i][1] are bidirectionally connected with an edge that takes B[1][2] time to go through it.
The third argument of input contains a 2-d matrix of size K x 2, C, where Node C[i][0] has a restaurant that has C[i][1] satisfaction.
Output Format: Return an integer representing the number of people who will have a dinner at the restaurant.
Constraints:
2 <- N <- 50000
1 <= M <= 100000
Output Format:
Return an integer representing the number of people who will have a dinner at the restaurant.
Constraints:
2 < N <- 50000
1 <= M <= 100000
1 <= K, B[i][e], 8[i][1] <= N
1 <= B[i][2] <= 1e4
1 <= C[i][1] <= 1e9
Example:
Input 1: A=4 B = [ [1, 2, 2], [2, 4, 1], [4, 3, 10], [3, 1, 1] ] C = [ [1, 1] ]
Output 1: 2
Explanation 1: Policemen at Node 1 and Node 3 will have a meal at node 1 without wasting any time.
Carl is bored of playing with ordinary prime numbers . Thus he comes up woth pecial numbers called Omega Primes. A number X is called Omega Prime , if there exists no perfect square Y (Y>1) such that Y divides X
For example 6 is an Omega Prime because there is no perfect square 1 that divides 6 . On the other hand ,12 is not Omega Prime as 4 (which is a perfect square ) is divisor of 12
Carl decides to play a bot more with Omga primes . He has an Array A of integers . Carl wants to find the number of different subsets such that the product of elements for each subset , results in an Omega Prime . Help Carl find this number .
since this number can be large , output the answer modulo 10^9 + 7
1<= Length of A <= 2 * 10 ^4
1 <= A[i] <= 30
The first argument is the integer array A
Return an integer denoting the number of dieffernt desired subsets modulo 10^9 + 7
A = [2,4,3]
A= [2 ,2, 2]
Output 1 :
3
Output 2:
3
Explanation 1:
The different subsets are [0,2] , [0] , [2]. (the numbers denote the number of indcies n the array of elements )
Explanation 2:
The different subsets are : [0], [1] , [2]
You live in Orange town. There are a lot of markets around that are connected with roads. These markets sell oranges at some prices. The town is not very well developed and they still use carts to transport goods from one place to the other. The roads connect two markets together and have one attribute associated with them. The attribute is the price to go from one market to the other in an empty cart. The town also has a tax factor, the tax factor is the number by which the price associated with a road needs to be multiplied, so it can go from one market to the other IF you are carrying oranges in your cart. So if a road's original price was 5 coins and tax factor of the town was 6 then in an empty cart it would take 5 coins to travel the road but if the cart contained oranges, it would cost 5 x 6 = 30 coins.
You wonder what would be the cheapest way to buy oranges if you were initially at each market. You can either buy at the market you're at or travel to some other market, buy oranges there, and travel back to the original market.
You are given an integer A denoting the number of total markets in orange town.
An integer array B denoting the price of purchasing oranges at each market.
A 2-D array C containing the information about the roads where each row contains three values.
The first two values denote the market numbers that are bi-directionally connected via a road and the third value is the price.
You are also given an integer D, this is the tax factor for the Orange town.
Find and return the required array where each element is the minimum cost to buy oranges at each market such that the starting and ending point is that market.
2 <= A <= 105
B.size() == A
1 <= B[i] <= 10^7
1 <= C.size() <=2*10^5
1 <= C[0], C[1] <= A
1 <= C[2] <= 10^3
1 <=D <= 5
The first argument is the integer A.
The second argument is the integer array B.
The third argument is the 2-D integer array C.
The fourth argument is the integer D.
Return an integer array as per the given problem.
Input 1:
A = 4
B = [3, 1, 10, 11
C = [[2, 1, 2], [3, 1, 2], [4, 1, 4], [3, 2, 1], [4, 2, 2], [4, 3, 1]]
D = 1
Input 2:
A = 2
B = [1, 3]
C = [[2, 1, 3]]
D = 1
Output 1:
[3, 1, 3, 1]
Output 2:
[1, 3]
SC
Explanation 1:
For 1st, 2nd, and 4th market, there is no better way. For the third market, since 3 and 2 are connected with a road that costs only 1. We can use that road to travel to 2 for cost 1 and buy oranges from market 2 for cost 1, and travel back for cost 11 for a final cost of 3. Explanation 2:
1 and 3 are already their respective minimum costs.