思路:裸的最短路,就是GM要转换成数字一下,跑M次dijkstra。
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll inff = 0x3f3f3f3f3f3f3f3f;
#define FOR(i,a,b) for(int i(a);i<=(b);++i)
#define FOL(i,a,b) for(int i(a);i>=(b);--i)
#define REW(a,b) memset(a,b,sizeof(a))
#define inf int(0x3f3f3f3f)
#define si(a) scanf("%d",&a)
#define sl(a) scanf("%I64d",&a)
#define sd(a) scanf("%lf",&a)
#define ss(a) scanf("%s",a)
#define mod int(1e9+7)
#define lc (d<<1)
#define rc (d<<1|1)
#define P pair<int,int>
#define pi acos(-1)
struct as{
int x;
int v;};
int d[100008];
vector<as>g[100008];
int n,m,k,q,w,qw,qwe;
string a,b;
int pp(string a)
{
int l=a.size(),s=0,t=1;
FOR(i,0,l-1)
{
if(a[i]=='G')
{
FOL(j,l-1,i+1)
{
s+=(a[j]-'0')*t;
t*=10;
}
return n+s;
}
}
FOL(i,l-1,0)
{
s+=(a[i]-'0')*t;
t*=10;
}
return s;
}
void djk(int s)
{
priority_queue<P,vector<P>,greater<P>>q;
REW(d,inf);
d[s]=0;
q.push(P(0,s));
while(q.size())
{
P p=q.top();q.pop();
int v=p.second;
if(d[v]<p.first) continue;
int ss=g[v].size();
FOR(i,0,ss-1)
{
as e=g[v][i];
if(d[e.x]>d[v]+e.v)
{
d[e.x]=d[v]+e.v;
q.push(P(d[e.x],e.x));
}
}
}
}
int main()
{
cin.tie(0);
si(n),si(m),si(k),si(q);
while(k--)
{
cin>>a>>b>>w;
qw=pp(a),qwe=pp(b);
if(w<=q)
{
g[qw].push_back(as{qwe,w});
g[qwe].push_back(as{qw,w});
}
}
double ss=0,dd=0,rt=0;
FOR(i,n+1,n+m)
{
int po=0;
djk(i);
FOR(j,1,n)
{
if(d[j]>q)
{
po++;break;
}
}
if(po) continue;
else
{
int rty=0;
int sss=inf;
FOR(j,1,n)
{
rty+=d[j];
sss=min(sss,d[j]);
}
double ddd=1.0*rty/n;
if(ss<=sss)
{
if(ss<sss) ss=sss,dd=ddd,rt=i;
else
{
if(ddd<dd) ss=sss,dd=ddd,rt=i;
}
}
}
}
if(dd==0) cout<<"No Solution"<<endl;
else
{
cout<<"G"<<rt-n<<endl;
printf("%.1lf %.1lf\n",ss,dd);
}
return 0;
}