呃...先跪谢巨佬!!!
蒟蒻发现stack和top那块编译通过不了
下面是错误的代码
#include<bits/stdc++.h>
using namespace std;
int n,m;
int c[10005],r[10005];
int gcd(int a,int b)
{
if(b==0)
return a;
else
return gcd(b,a%b);
}
int head[10005];
struct Edge
{
int to;
int next;
};
Edge edge[10005];
int tot;
void add(int x,int y)
{
tot++;
edge[tot].to=y;
edge[tot].next=head[x];
head[x]=tot;
}
struct DP
{
int zi;
int mu;
};
DP dp[10005];
int stack[10005],top;
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>c[i];
for(int j=1;j<=c[i];j++)
{
int y;
cin>>y;
r[y]++;
add(i,y);
}
if(r[i]==0)
{
top++;
stack[top]=i;
dp[i].zi=dp[i].mu=1;
}
}
while(top)
{
int t=stack[top];
top--;
for(int i=head[t];i;i=edge[i].next)
{
int to=edge[i].to;
int zi=dp[t].zi*dp[to].mu+dp[to].zi*dp[t].mu*c[t];
int mu=dp[t].mu*c[t]*dp[to].mu;
int chu=gcd(zi,mu);
dp[to].zi=zi/chu;
dp[to].mu=mu/chu;
r[to]--;
if(r[to]==0)
{
top++;
stack[top]=to;
if(c[to]==0)
{
cout<<dp[to].zi<<' '<<dp[to].mu<<endl;
}
}
}
}
return 0;
}