//并查集一般使用,int find(int x)+p[N]+struct Edge{}+unordered_set<int> s+vector<int> v;
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<unordered_set>
using namespace std;
const int N=10010;
int n;
int p[N], c[N],hc[N],ha[N];
unordered_set<int> s;
struct Edge
{
int a,b;
}e[N];
struct Family
{
int id,c,hc,ha;
};
bool cmp(Family a,Family b)
{
//if(a.ha/a.c!=b.ha/b.c) return a.ha/a.c>b.ha/b.c;
if(a.ha*b.c!=b.ha*a.c) return a.ha*b.c>b.ha*a.c;//分数比较大小,可能不精确,转化为乘法
else return a.id<b.id;
}
int find(int x)
{
if(p[x]!=x) p[x]=find(p[x]);
return p[x];
}
int main()
{
cin>>n;
int m=0;
for(int i=0;i<n;i++)
{
int id,father,mother,k;
cin>>id>>father>>mother>>k;
s.insert(id);
if(father!=-1)
{
e[m++]={id,father};
//e[m].a=id,e[m].b=father;
// m++;
s.insert(father);
}
if(mother!=-1)
{
e[m++]={id,mother};
s.insert(mother);
}
for(int j=0;j<k;j++)
{
int son;
cin>>son;
e[m++]={id,son};
s.insert(son);
}
cin>>hc[id]>>ha[id];
}
for(int i=0;i<N;i++) p[i]=i,c[i]=1;
for(int i=0;i<m;i++)
{
int a=e[i].a,b=e[i].b;
int pa=find(a),pb=find(b);
if(pa!=pb)
{
if(pa<pb) swap(pa,pb); //让编号最小的成为祖宗
c[pb]+=c[pa]; //并查集合并的时候,维护的数组也合并
hc[pb]+=hc[pa];
ha[pb]+=ha[pa];
p[pa]=pb;
}
}
vector<Family> family;
for(auto S:s) //判断是不是家庭祖宗
if(find(S)==S) family.push_back({S,c[S],hc[S],ha[S]});
sort(family.begin(),family.end(),cmp);
cout<<family.size()<<endl;
for(auto f:family)
printf("%04d %d %.3lf %.3lf\n",f.id,f.c,(double)f.hc/f.c,(double)f.ha/f.c);
return 0;
}