深刻的教训,不要写错读入
#include <cstdio>
#include <algorithm>
using namespace std;
const int MAXN = ;
const int MAXM = ;
int cnt=,u[MAXM],v[MAXM],w[MAXM],first[MAXN],next[MAXM];
int dis[MAXN],st,ans=,n,fa[MAXN];
inline int qread(void){
int x=;
char s;
s=getchar();
while(s>''||s<'')
s=getchar();
while(s>=''&&s<=''){
x*=;
x+=s-'';
s=getchar();
}
return x;
}
inline void qwrite(int x){
if(x>){
qwrite(x/);
}
putchar(x%+'');
}
void addedge(int ux,int vx,int wx){
++cnt;
u[cnt]=ux;
v[cnt]=vx;
w[cnt]=wx;
next[cnt]=first[ux];
first[ux]=cnt;
}
void dfs2(int x,int f){
for(int i=first[x];i;i=next[i]){
if(v[i]==f)
continue;
fa[v[i]]=w[i];
dfs2(v[i],x);
dis[x]=max(dis[v[i]]+w[i],dis[x]);
}
if(dis[x]+fa[x]>st){
ans++;
dis[x]=;
}
}
int main(){
n=qread();
int m=;
for(int i=;i<=n;i++){
int mid;
mid=qread();
for(int j=;j<=mid;j++){
int vx,wx;
vx=qread();
wx=qread();
addedge(i,vx,wx);
m=max(m,wx);
}
}
st=qread();
if(m>=st){
printf("No solution.\n");
return ;
}
dfs2(,);
qwrite(ans);
return ;
}