比赛 NOIP模拟赛by mzx Day2 评测结果 MMMMMMMMMM
题目名称 森林大礼包 最终得分 0
用户昵称 mybing 运行时间 0.000 s
代码语言 C++ 内存使用 0.00 MiB
提交时间 2016-10-20 20:46:52
显示代码纯文本
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<iomanip>
  4. #include<string>
  5. #include<cstring>
  6. #include<algorithm>
  7. using namespace std;
  8. int a,x[100000],p,w[10000],q[10000][10000],h[10000]={0},t=0;
  9. int wx=1000000007;
  10. int main()
  11. {
  12. freopen("three_squirrels.in","r",stdin);
  13. freopen("three_squirrels.out","w",stdout);
  14. cin>>a;
  15. x[0]=1;
  16. h[0]=1;
  17. for(int i=1;i<=a;i++)
  18. {
  19. cin>>w[i];
  20. for(int j=1;j<=w[i];j++)
  21. cin>>q[i][j];
  22. }
  23. for(int k=1;k<=a;k++)
  24. {
  25. for(int i=1;i<=a;i++)
  26. {
  27. t=0;
  28. if(h[i]==1) continue;
  29. for(int j=1;j<=w[i];j++)
  30. {
  31. if(h[q[i][j]]==1) t++;
  32. }
  33. if(t==w[i])
  34. {for(int j=1;j<=w[i];j++)
  35. {x[i]=((x[i]%wx)+(x[q[i][j]]%wx))%wx;}
  36. h[i]=1;
  37. }
  38. }
  39. int l=0;
  40. for(int i=1;i<=a;i++)
  41. {
  42. if(h[i]==1) l++;
  43. }
  44. if(l==a) break;
  45. }
  46. cout<<x[a]<<endl;
  47. return 0;
  48. }