4Question 2: Need For Speed 4.1Introduction Lukarp has started his own tech company. He…
- User
4Question 2: Need For Speed 4.1Introduction Lukarp has started his own tech company. He received a lot of funding from Igen with which he opened many offices around the world. Each office needs to communicate with one other, for which they’re using high speed connections between the offices. Office number 1 is Lukarp’s HQ. Some offices are important and hence need faster connections to the HQ for which Lukarp has use special fiber connections. Lukarp has already planned the connections but feels some fiber connections are redundant. You have been hired by Lukarp to remove those fiber connections which don’t cause faster connections. 4.2Problem Statement 4.2.1The Problem The offices and (bi-directional) connections (both normal and fiber) are given to you. HQ is numbered as 1. The ith normal connection connects any two offices ai and bi . Normal connections have latency li . The ith fiber connection connects the HQ with the office ci . Fiber connections also come with a latency pi . The total latency of a path is the sum of latencies on the connections. You are to output the maximum number of fiber connections that can be removed, such that the latency of the smallest latency path between the HQ and any other node remains the same as before. • There are n offices with m normal connections and k high-speed fiber connections. • The ith normal connection connects offices ai and bi (bi-directionally) with latency li . • The ith fiber connection connects offices 1 and ci (bi-directionally) with latency pi . 4.2.2 Input Format The first line of the input file will contain three space-separated integers n, m and k, the number of offices, the number of normal connections and the number of fiber connections. There will be m lines after this, the ith line signifying the ith normal connection, each containing three space-separated integers ai , bi and li the two offices that are connected and the latency of the connection respectively. There will be k lines after this, the ith line signifying the ith fiber connection, each containing three space-separated integers ci and pi , the office connected to the HQ and the latency of the fiber connection respectively. 64.2.3 Output Format Output only one integer m - the maximum number of fiber connections that can be removed without changing the latency of smallest latency path from office 1 to any other office. 4.2.4 Constraints • 2 ≤ n ≤ 105 • 1 ≤ m ≤ 2 · 105 • 1 ≤ k ≤ 105 • 1 ≤ ai , bi , ci ≤ n • 1 ≤ li , pi ≤ 109 4.2.5 Example Input: 4 5 2 1 2 2 1 4 9 1 3 3 2 4 4 3 4 5 3 4 4 5 Output: 1 Explanation: In this example, there are five normal connections as shown in the figure below. The fiber connection going from 1 to 3 can be removed because the normal con- nection (3) is faster than the fiber connection (4). However, the fiber connection with 4 cannot be removed. Hence the maximum number of fiber connections that can be removed is 1. also keep into consideration that a fiber path to node A can be a part of the shortest path to node B
give c++ code you can do it using a struct and dijkstra . dont use many advanced functions of c++. try to keep it beginner level code. dont worry about time efficiency.
- Assistant
- User
keep into consideration that a fiber path to node A can be a part of the shortest path to node B
- Assistant
- User
us this algorithm. make an initial shortest distance array for all nodes. also make a path array for each node.now keep a count array of n size and keep count of number of fibres that can be removed by following this algorithm- first start from 1st fiber that is greater than or equal to normal, now check for every node that has that particular fiber connection in its path
- Assistant
- User
give full c++ code
- Assistant