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. C#之父 Anders Hejlsberg

             Anders Hejlsberg (born December 1960)[2] is a prominent Danish software engineer who co-des ...

  2. Hibernate总结--MyEclipse的小bug

    今天笔者在写一个用S2SH的程序的时候,出现了下面的错误: org.springframework.beans.factory.BeanCreationException: Error creatin ...

  3. Struts2_搭建环境及HelloWorld

  4. Linux学习笔记---【1】

    什么是POSIX? 为何说Linux使用POSIX对于开发有很好的影响? POSIX是可携式操作系统接口(Portable Operating System Interface)的缩写,重点在于规范内 ...

  5. Centos6的VSFTP服务器配置使用教程

    Centos 6 的VSFTP 关闭SELinux,在终端机输入 vi /etc/selinux/config SELINUX=enforcing 改成 SELINUX=disabled 关闭seli ...

  6. iOS-Andriod百度地图仿百度外卖-饿了么-选择我的地址-POI检索/

    http://zanderzhang.gitcafe.io/2015/09/19/iOS-Andriod百度地图仿百度外卖-饿了么-选择我的地址-POI检索/ 百度外卖选择送货地址: 饿了么选择送货地 ...

  7. 20140213-想念是while里的死循环

    // stdafx.h : 标准系统包含文件的包含文件,// 或是经常使用但不常更改的// 特定于项目的包含文件// #pragma once#include "targetver.h&qu ...

  8. JAVA(int...i)问题

    第一次看到这种写法,弄不明白到底会是神马结果,运行后才发现是这么的神奇. 无论你调用的方法中带几位参数,“hello”一直可以被输出.

  9. JSLint notepad++使用

    1.JSLint简介 JSLint定义了一组编码约定,这比ECMA定义的语言更为严格.这些编码约定汲取了多年来的丰富编码经验,并以一条年代久远的编程原则 作为宗旨:能做并不意味着应该做.JSLint会 ...

  10. javascript弹窗基础篇

    confirm()意既确认框 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> ...