rt。
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define re register
#define endl '\n'
#define inf 2147483647
#define MAXN 10005
#define MAXM 10005
int n,s,t,ww;
char uu,vv;
int tot;
struct edge {int v,w,nex;};
edge e[MAXM];
int head[MAXN],dis[MAXN];
int ans=inf;
char ansid;
inline void add(int u,int v,int w) {e[++tot]=(edge){v,w,head[u]};head[u]=tot;}
struct node {
int u,d;
bool operator <(const node& as)const {return d>as.d;}
};
inline void dijkstra() {
for (re int i=1;i<=n;i++) dis[i]=inf;
dis[s]=0;
priority_queue<node>q;
q.push((node){s,0});
while (!q.empty()) {
int u=q.top().u,d=q.top().d;q.pop();
if (d!=dis[u]) continue;
for (re int i=head[u];i;i=e[i].nex) {
int v=e[i].v,w=e[i].w;
if (dis[u]+w<dis[v]) {dis[v]=dis[u]+w;q.push((node){v,dis[v]});}
}
}
}
inline int val(char ch) {return ch>='A'&&ch<='Z'?27+ch-'A':1+ch-'a';}
int main() {
cin>>n;s=val('Z');
while (n--) {
cin>>uu>>vv>>ww;
add(val(uu),val(vv),ww);
add(val(vv),val(uu),ww);
}
dijkstra();
for (re char i='A';i<='Z';i++){
if (dis[val(i)]<ans) ans=dis[val(i)],ansid=i;
//cout<<dis[val(i)]<<endl;
}
cout<<ansid<<" "<<ans<<endl;
return 0;
}