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

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

【code】:

 #include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <queue> using namespace std;
#define MOD 1000000007 struct Nod
{
int parent;
long long sum;
int edge;
int son_cnt;
}node[],temp; int n;
int a[],b[],vis[]; void init()
{
int i;
for(i=;i<=n;i++)
{
node[i].parent=-;
node[i].sum=;
node[i].edge=;
node[i].son_cnt=;
}
} int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
init();
int i;
for(i=;i<n;i++)
{
scanf("%d",a+i);
}
for(i=;i<n;i++)
{
scanf("%d",b+i);
}
memset(vis,,sizeof(vis));
for(i=;i<n;i++)
{
node[i].parent=a[i];
node[i].edge=b[i];
node[a[i]].son_cnt++;
}
queue<Nod> Q;
for(i=;i<n;i++)
{
if(node[i].son_cnt==)
{
node[i].sum = ;
Q.push(node[i]);
}
} while(!Q.empty())
{
temp = Q.front();
Q.pop();
if(temp.parent==-) break;
node[temp.parent].sum+=(temp.sum*temp.edge)%(MOD*);
node[temp.parent].son_cnt--;
if(node[temp.parent].son_cnt==)
{
Q.push(node[temp.parent]);
}
}
if(node[].sum%==)
{
puts("FREAK OUT");
}
else
{
printf("%lld\n",node[].sum%MOD);
}
}
return ;
}

bnuoj 33648 Neurotic Network(树形模拟题)的更多相关文章

  1. 剑指Offer——网易校招内推笔试题+模拟题知识点总结

    剑指Offer--网易校招内推笔试题+模拟题知识点总结 前言 2016.8.2 19:00网易校招内推笔试开始进行.前天晚上利用大约1小时时间完成了测评(这个必须做,关切到你能否参与面试).上午利用2 ...

  2. 8.22 NOIP 模拟题

      8.22 NOIP 模拟题 编译命令 g++ -o * *.cpp gcc -o * *.c fpc *.pas 编译器版本 g++/gcc fpc 评测环境 位 Linux, .3GHZ CPU ...

  3. Capture the Flag ZOJ - 3879(模拟题)

    In computer security, Capture the Flag (CTF) is a computer security competition. CTF contests are us ...

  4. poj 1008:Maya Calendar(模拟题,玛雅日历转换)

    Maya Calendar Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 64795   Accepted: 19978 D ...

  5. poj 1888 Crossword Answers 模拟题

    Crossword Answers Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 869   Accepted: 405 D ...

  6. CodeForces - 427B (模拟题)

    Prison Transfer Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Sub ...

  7. sdut 2162:The Android University ACM Team Selection Contest(第二届山东省省赛原题,模拟题)

    The Android University ACM Team Selection Contest Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里 ...

  8. 全国信息学奥林匹克联赛 ( NOIP2014) 复赛 模拟题 Day1 长乐一中

    题目名称 正确答案  序列问题 长途旅行 英文名称 answer sequence travel 输入文件名 answer.in sequence.in travel.in 输出文件名 answer. ...

  9. UVALive 4222 Dance 模拟题

    Dance 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&pag ...

随机推荐

  1. 结合setTimeout和clearTimeout,实现“返回顶部”的功能

    结合setTimeout和clearTimeout,当页面停止滚动时,“返回顶部”按钮淡隐淡出.点击“返回顶部”页面以动画形式返回顶部.完美兼容ie6-11,firefox,chrome等. html ...

  2. 破解软件感悟-PE文件格式之实例总结(五)

    有很多介绍PE文件的文章,但是我打算写一篇关于输入表的文章,因为它对于破解很有用.     我想解释它的最好的方法是举一个例子,你可以跟着我逐步深入,一步一步的思考,最后你将完全明白,我选择了一个我刚 ...

  3. PAT1014——福尔摩斯的约会

    大侦探福尔摩斯接到一张奇怪的字条:“我们约会吧! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hyscvnm”.大侦探很快就明白了,字条 ...

  4. C#中调用API

    介绍 API( Application Programming Interface ),我想大家不会陌生,它是我们Windows编程的常客,虽然基于.Net平台的C#有了强大的类库,但是,我们还是不能 ...

  5. DOS删除服务

    启动服务:   net   start   服务名   停止服务:   net   stop     服务名   卸载服务:   服务名   -uninstall 安装服务:sc create ser ...

  6. 一个小makefile程序

    刚刚开始学习linux下的程序,总需要自己写一些小型的makefile文件,这里给出一个makefile的例子,方便以后借鉴. 程序包含了main.c(需要头文件input.h 和 display.h ...

  7. acount

    #include<iostream> using namespace std; class account { public: int de( int i, double b, doubl ...

  8. C89 和 C99的标准比较

    本文转载自: C89和C99标准比较  原文转载自: http://blog.programfan.com/article.asp?id=14051  http://blog.csdn.net/xgb ...

  9. python 中range与xrange的区别

    先来看看range与xrange的用法介绍 help(range)Help on built-in function range in module __builtin__: range(...) r ...

  10. c# 取得ip地址和网关

    /// <summary> /// 得到本机IP /// </summary> private string GetLocalIP() { //本机IP地址 string st ...