Savita And Friends
Difficulty: Hard

After completing her final semester, Savita is back home. She is excited to meet all her friends. Her $N$ friends live in different houses spread across the city.    

There are $M$ roads connecting the houses. The road network formed is connected and does not contain self loops and multiple roads between same pair of houses. Savita and Friends decide to meet.  

Savita wants to choose a point(not necessarily an integer) $P$ on the road numbered $K$, such that, the maximum of $dist(i)$ for all $1 \leq i \leq N$ is minimised,  
where $dist(i)$ is the shortest distance between the $i$'<sup>th</sup> friend and $P$.    

If $K$'th road connects friend $A$ and friend $B$ you should print distance of chosen point from $A$. Also, print the $max(dist(i))$ for all $1 \leq i \leq N$. If there is more than one solution, print the one in which the point $P$ is closest to $A$.     

Note: 

+ Use scanf/printf instead of cin/cout. Large input files.
+ Order of $A$ and $B$ as given in the input must be maintained. If P is at a distance of 8 from $A$ and 2 from $B$, you should print 8 and not 2.  


Input Format:
First line contain $T$, the number of testcases.   
T testcases follow.  
First Line of each testcase contains 3 space separated integers $N, M, K$ .  
Next $M$ lines contain description of the $i$<sup>th</sup> road : three space separated integers $A, B, C$, where $C$ is the length of road connecting $A$ and $B$.      


Output Format:
For each testcase, print two space separated values in one line. The first value is the distance of $P$ from the point $A$ and the second value is the maximum of all the possible shortest paths between $P$ and all of Savita's and her friends' houses. Round both answers to $5$ decimal digits and print exactly $5$ digits after the decimal point.   


Sample Input:
    2
    2 1 1
    1 2 10
    4 4 1
	1 2 10
	2 3 10
	3 4 1
	4 1 5


Sample Output:
    5.00000 5.00000
    2.00000 8.00000


Python 3 starter code:
#
# Complete the 'solve' function below.
#
# The function is expected to return a DOUBLE_ARRAY.
# The function accepts following parameters:
#  1. INTEGER n
#  2. INTEGER k
#  3. 2D_INTEGER_ARRAY roads
#

def solve(n, k, roads):
    # Write your code here




Reference solution (C++):
###C++  
```cpp  
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef long long LL;
typedef pair< LL , LL> PII;
typedef vector<PII> VPII;
typedef vector<LL> VI;
const LL INF = 1000000000000000000ll;
vector<PII> edges[100009];
VI dijk(int N, int s)
{
    priority_queue<PII, vector<PII>, greater<PII> > Q;
    vector< LL > dist(N, INF), dad(N, -1);
    Q.push (make_pair (0ll, (LL)s));
    dist[s] = 0;
    while (!Q.empty()){
        PII p = Q.top();
        Q.pop();
        LL here = p.second;
        for (vector<PII>::iterator it=edges[here].begin(); it!=edges[here].end(); it++){
            if (dist[here] + it->first < dist[it->second]){
                dist[it->second] = dist[here] + it->first;
                dad[it->second] = here;
                Q.push (make_pair (dist[it->second], it->second));
            }
        }
    }
    return dist;
}
int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        LL N,M,s,a,b,c,K,s1,s2,l;
        scanf("%lld %lld %lld",&N,&M,&K);
        for(int i=0; i<100009; i++)
            edges[i].clear();
        for(int i=0; i<M; i++)
        {
            scanf("%lld %lld %lld",&a,&b,&c);
            a--,b--;
            edges[a].push_back(make_pair(c,b));
            edges[b].push_back(make_pair(c,a));
            if(i==K-1)
                s1=a,s2=b,l=c;
        }
        vector < LL > dist1=dijk(N,s1);
        vector < LL > dist2=dijk(N,s2);
    /*    for(int i=0; i<N; i++)
            printf("%lld ",dist1[i]);
        cout << endl;
        for(int i=0; i<N; i++)
            printf("%lld ",dist2[i]);
        cout << endl;*/
        VPII fin;
        for(int i=0; i<N; i++)
            fin.pb(mp(dist1[i],dist2[i]));
        sort(fin.begin(),fin.end());
        LL prevx=-1,prevy=-1;
        VPII w;
        for(int i=N-1; i>=0; i--)
        {
            if(fin[i].F <= prevx && fin[i].S <= prevy)continue;
            prevx=fin[i].F;
            prevy=fin[i].S;
            w.push_back(fin[i]);
        }
        int P=w.size();
        //    sort(w.begin(),w.end());
        double ans=min(w[0].F,w[P-1].S),finans;
        if(w[0].F<=w[P-1].S)finans=0;
        else finans=l;
        for(int i=0; i<P-1; i++)
        {
            double tmp = (w[i].second - w[i+1].first + l) / 2.0;
            double val= w[i+1].first+tmp;
            if(val<ans)ans=val,finans=tmp;
            else if(val==ans)finans=min(finans,tmp);
        }
        printf("%.5lf %.5lf\n",(double)finans,(double)ans);
    }
    return 0;
}
```