#include <bits/stdc++.h>
using namespace std;
int cnt = 0;
int min_distance(vector<int> &dist, vector<int> &vis, int n)
{
    int min = 100000;
    int min_index = -1;

    for (int v = 1; v <= n; v++)
    {
        if (vis[v] == 0 && dist[v] <= min)
        {
            min = dist[v], min_index = v;
        }
    }
    return min_index;
}
void dijkstra(vector<vector<int>> &graph, int src, int n, vector<int> &dist)
{
    vector<int> vis(n + 1, 0);

    for (int i = 1; i <= n; i++)
        dist[i] = 100000;
    dist[src] = 0;

    for (int count = 0; count < n; count++)
    {
        int u = min_distance(dist, vis, n);
        if (u == -1)
            break;

        vis[u] = 1;

        for (int v = 1; v <= n; v++)
        {
            if (vis[v] == 0 && graph[u][v] != 100000 &&
                dist[u] != 100000 && dist[u] + graph[u][v] < dist[v])
            {
                dist[v] = dist[u] + graph[u][v];
            }
        }
    }
}

void add_edge(vector<vector<int>> &adj, int u, int v, int l)
{
    if (u >= 1 && u <= adj.size() - 1 && v >= 1 && v <= adj.size() - 1)
    {
        adj[u][v] = l;
        adj[v][u] = l;
    }
}

void func(vector<vector<int>> &adj1, vector<int> &dist1, vector<int> &adj2, int n)
{
    
    // int cnt = 0;
    for (int i = 1; i <= n; i++)
    {
           cout << "adj2[i] is "  << adj2[i]<< endl;
 
            if (adj2[i]!=100000 && dist1[i] <= adj2[i])
            
            {
                cnt++;
            }
        else
        {
                       cout << "chsnging  dist of " << i << " to " << adj2[i] << "from"<< dist1[i]<< endl;
            dist1[i] = adj2[i];
   
            add_edge(adj1, 1, i, dist1[i]);

            cout << "changed dist of " << i << " is " << dist1[i] << endl;
            dijkstra(adj1, 1, n, dist1);
        }
        
     for (int i = 0; i < dist1.size(); i++)
    {
        cout << i << "dist 1 array" << dist1[i] << endl;
    }
            cout<<"node is "<<i<<endl;
            cout<<"count is " <<cnt<<endl;

   }
    
    cout << cnt << endl
         << endl;
}

int main()
{
    int n, m, k;
    cin >> n >> m >> k;
    vector<vector<int>> adj1(n + 1, vector<int>(n + 1, 100000));
    // vector<vector<int>> adj2(n + 1, vector<int>(n + 1, 100000));
    vector<int> adj2(n, 100000);
    vector<int> dist1(n + 1, 100000), dist2(n + 1, 100000);

    for (int i = 0; i < m; i++)
    {
        int u, v, l;
        cin >> u >> v >> l;
        add_edge(adj1, u, v, l);
    }

    for (int i = 0; i < k; i++)
    {
        int v, l;
        cin >> v >> l;
        if (adj2[v] != 100000)
        {
            cnt++;
            if (adj2[v] > l)
            {
                adj2[v] = l;
            }
        }
        else
            adj2[v] = l;
        //  add_edge(adj2, 0, v, l);
    }
    
    cout << "count siisisis" << cnt << endl;

    dijkstra(adj1, 1, n, dist1);
    // dijkstra(adj2, 1, n, dist2);
    cout << "initially the shortest paths are" << endl
         << endl;
         
         
         
    for (int i = 0; i < dist1.size(); i++)
    {
        cout << i << " " << dist1[i] << endl;
    }
    
    
    
    
    cout << endl
         << endl;
        for (int i = 0; i < dist1.size(); i++)
    {
        cout << i << " " << dist1[i] << endl;
    }
    
    
        for (int i = 0; i < dist1.size(); i++)
    {
        cout << i << "dist 1 array" << dist1[i] << endl;
    }
         
    for (int i = 0; i <= adj2.size(); i++)
    {
        cout << i << "adj 2 array" << adj2[i] << endl;
    }
    func(adj1, dist1, adj2, n);

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





4 Question 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.
7




all test cases are working when i check manually but online judje is throwing wrong answer for hidden test case what could be wrong