uestion 2: Need For Speed 4.1 Introduction Lukarp has started his own tech company. He…
- User
uestion 2: Need For Speed 4.1 Introduction 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.2 Problem Statement 4.2.1 The 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. 6 4.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: 452 122 149 133 244 345 34 45 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.
need c++ implementations also there can be multiple fibres and multiple normal connection between two nodes also after updating a fible connection maybe another fibre connection become redundant , this case also needs to be handled
- Assistant
- User
4 4 2 2 3 2 2 4 8 4 3 3 1 4 5 3 7 2 9 this test case answer is giving 0 it should give 1, issue if after updating fibre 3 with weight 7 , fibke 9 becomes redundant as 1 to 3 is 9 and we ned to remove the 9 fible as its eqal
- Assistant
- User
give me c++ implentation with refined approach
- Assistant
- User
explain tthe code
- Assistant