#include <iostream>
#include <sstream>
#include <string>
#include <sstream>
#include <cstdio>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <map>
#include <set>
#define maxm 2010
#define inf 0x3fffffff
using namespace std;
map<int,string> intToString;
map<string, int>stringToInt;
map <string,int> gang;
bool vis[maxm]={false};
int m,k;
int G[maxm][maxm]={0};
int weight[maxm]={0};
int num=0,mid=0,totalv=0,mweight=0,cnt=0;
void store(string s){
if(stringToInt.find(s)==stringToInt.end()){
stringToInt[s]=cnt;
intToString[cnt++]=s;
}
}
void BFS(int id){
num++;
vis[id]=true;
if(weight[id]>mweight){ //用weight[id]>weight[mid] 不行
mid=id;
mweight=weight[id];
}
for(int i=0;i<cnt;i++){
if(G[id][i]>0){
totalv+=G[id][i];
G[id][i]=G[i][id]=0;
if(vis[i]==false){
BFS(i);
}
}
}
}
int main()
{
cin>>m>>k;
string s1,s2;
int a,b,t;
for(int i=0;i<m;i++){
cin>>s1>>s2>>t;
store(s1);
store(s2);
a=stringToInt[s1];
b=stringToInt[s2];
weight[a]+=t;
weight[b]+=t;
G[a][b]+=t;
G[b][a]+=t;
}
for(int i=0;i<cnt;i++){
if(vis[i]==false){
BFS(i);
if(num>2&&totalv>k){
gang[intToString[mid]]=num;
}
num=mid=totalv=mweight=0;
}
}
cout<<gang.size()<<endl;
for(auto it=gang.begin();it!=gang.end();it++){
cout<<it->first<<" "<<it->second<<endl;
}
return 0; //注意题中不一定为AAA,可以为ACB
}
看晴神代码写的,因为没思路。。。。晴神柳神伴我成长T_T