Example

Input

2 10
Warsaw Petersburg
3
Kiev Moscow Petersburg
150 120
3
Moscow Minsk Warsaw
100 150


Output

380 1
#include<bits/stdc++.h>

using namespace std;

constexpr long long INF64 = 1e18;

using Weight=long long;

struct Edge{
    int src,dst;
    Weight weight;
	int belong,kaisuu;
    Edge(int src,int dst,Weight weight,int belong,int kaisuu):
    src(src),dst(dst),weight(weight),belong(belong),kaisuu(kaisuu){}
};

auto operator < (const Edge &e,const Edge &f){
    if(e.weight!=f.weight)return e.weight>f.weight;
    else if(e.kaisuu!=f.kaisuu)return e.kaisuu>f.kaisuu;
    else return e.dst<f.dst;
}

using Edges=vector<Edge>;
using Graph=vector<Edges>;

pair<Weight,int> dijkstra(const Graph &g,int s,int t,int N,int T){
    const int V=g.size();
	vector<vector<Weight>>dist(V,vector<Weight>(N,INF64));
	vector<vector<int>>prev(V,vector<int>(N,-1));
    priority_queue<Edge>q;
    for(int i=0;i<N;++i)dist[s][i]=0;
    for(q.emplace(-2,s,-T,-1,-1);!q.empty();){
        Edge e=q.top();q.pop();
        if(e.belong>=0){
			if(prev[e.dst][e.belong]!=-1)continue;
			else prev[e.dst][e.belong]=e.src;
		}
        if(e.dst==t)return make_pair(e.weight,e.kaisuu);
        for(auto ge:g[e.dst]){
			int plus=0;
			if(e.belong!=ge.belong)plus=T;
            if(dist[ge.dst][ge.belong] > e.weight+ge.weight+plus){
                dist[ge.dst][ge.belong]=e.weight+ge.weight+plus;
				if(plus)plus=1;
                q.emplace(ge.src,ge.dst,dist[ge.dst][ge.belong],ge.belong,e.kaisuu+plus);
            }
        }
    }
	return make_pair(-1,-1);
}


int main(){
	int N,T;
	cin>>N>>T;
	string A,B;
	cin>>A>>B;
	map<string,int>mp;
	int k=1;
	Graph g(100001);
	for(int i=0;i<N;++i){
		int a;
		cin>>a;
		int prev=-1;
		vector<int>station(a);
		for(int j=0;j<a;++j){
			string s;
			cin>>s;
			if(mp[s]==0)mp[s]=k++;
			station[j]=mp[s];
		}
		for(int j=0;j<a-1;++j){
			Weight t;
			cin>>t;
			g[station[j]].emplace_back(station[j],station[j+1],t,i,-1);
			g[station[j+1]].emplace_back(station[j+1],station[j],t,i,-1);
		}
	}
	pair<Weight,int>ans=dijkstra(g,mp[A],mp[B],N,T);
	if(ans.first==-1)cout<<"-1"<<endl;
	else cout<<ans.first<<" "<<ans.second<<endl;
}