zoukankan      html  css  js  c++  java
  • bnuoj 33648 Neurotic Network(树形模拟题)

    http://www.bnuoj.com/bnuoj/problem_show.php?pid=33648

    【题解】:结果先对MOD*2取模,才能得到结果是否是正确的奇偶问题,得到最后结果之后再对MOD取模。。。

    【code】:

     1 #include <iostream>
     2 #include <stdio.h>
     3 #include <string.h>
     4 #include <algorithm>
     5 #include <queue>
     6 
     7 using namespace std;
     8 #define MOD 1000000007
     9 
    10 struct Nod
    11 {
    12     int parent;
    13     long long sum;
    14     int edge;
    15     int son_cnt;
    16 }node[10010],temp;
    17 
    18 int n;
    19 int a[10010],b[10010],vis[10010];
    20 
    21 void init()
    22 {
    23     int i;
    24     for(i=0;i<=n;i++)
    25     {
    26         node[i].parent=-1;
    27         node[i].sum=0;
    28         node[i].edge=0;
    29         node[i].son_cnt=0;
    30     }
    31 }
    32 
    33 int main()
    34 {
    35     int t;
    36     scanf("%d",&t);
    37     while(t--)
    38     {
    39         scanf("%d",&n);
    40         init();
    41         int i;
    42         for(i=1;i<n;i++)
    43         {
    44             scanf("%d",a+i);
    45         }
    46         for(i=1;i<n;i++)
    47         {
    48             scanf("%d",b+i);
    49         }
    50         memset(vis,0,sizeof(vis));
    51         for(i=1;i<n;i++)
    52         {
    53             node[i].parent=a[i];
    54             node[i].edge=b[i];
    55             node[a[i]].son_cnt++;
    56         }
    57         queue<Nod> Q;
    58         for(i=0;i<n;i++)
    59         {
    60             if(node[i].son_cnt==0)
    61             {
    62                 node[i].sum = 1;
    63                 Q.push(node[i]);
    64             }
    65         }
    66 
    67         while(!Q.empty())
    68         {
    69             temp = Q.front();
    70             Q.pop();
    71             if(temp.parent==-1) break;
    72             node[temp.parent].sum+=(temp.sum*temp.edge)%(MOD*2);
    73             node[temp.parent].son_cnt--;
    74             if(node[temp.parent].son_cnt==0)
    75             {
    76                 Q.push(node[temp.parent]);
    77             }
    78         }
    79         if(node[0].sum%2==0)
    80         {
    81             puts("FREAK OUT");
    82         }
    83         else
    84         {
    85             printf("%lld
    ",node[0].sum%MOD);
    86         }
    87     }
    88     return 0;
    89 }
  • 相关阅读:
    POJ 2752 Seek the Name, Seek the Fame
    POJ 2406 Power Strings
    KMP 算法总结
    SGU 275 To xor or not to xor
    hihocoder 1196 高斯消元.二
    hihoCoder 1195 高斯消元.一
    UvaLive 5026 Building Roads
    HDU 2196 computer
    Notions of Flow Networks and Flows
    C/C++代码中的笔误
  • 原文地址:https://www.cnblogs.com/crazyapple/p/3352416.html
Copyright © 2011-2022 走看看