bnuoj 33648 Neurotic Network(树形模拟题)
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(树形模拟题)的更多相关文章
- 剑指Offer——网易校招内推笔试题+模拟题知识点总结
剑指Offer--网易校招内推笔试题+模拟题知识点总结 前言 2016.8.2 19:00网易校招内推笔试开始进行.前天晚上利用大约1小时时间完成了测评(这个必须做,关切到你能否参与面试).上午利用2 ...
- 8.22 NOIP 模拟题
8.22 NOIP 模拟题 编译命令 g++ -o * *.cpp gcc -o * *.c fpc *.pas 编译器版本 g++/gcc fpc 评测环境 位 Linux, .3GHZ CPU ...
- Capture the Flag ZOJ - 3879(模拟题)
In computer security, Capture the Flag (CTF) is a computer security competition. CTF contests are us ...
- poj 1008:Maya Calendar(模拟题,玛雅日历转换)
Maya Calendar Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 64795 Accepted: 19978 D ...
- poj 1888 Crossword Answers 模拟题
Crossword Answers Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 869 Accepted: 405 D ...
- CodeForces - 427B (模拟题)
Prison Transfer Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Sub ...
- sdut 2162:The Android University ACM Team Selection Contest(第二届山东省省赛原题,模拟题)
The Android University ACM Team Selection Contest Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里 ...
- 全国信息学奥林匹克联赛 ( NOIP2014) 复赛 模拟题 Day1 长乐一中
题目名称 正确答案 序列问题 长途旅行 英文名称 answer sequence travel 输入文件名 answer.in sequence.in travel.in 输出文件名 answer. ...
- UVALive 4222 Dance 模拟题
Dance 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&pag ...
随机推荐
- Quartz.net官方开发指南系列篇
Quartz.NET是一个开源的作业调度框架,是OpenSymphony 的 Quartz API的.NET移植,它用C#写成,可用于winform和asp.net应用中.它提供了巨大的灵活性而不牺牲 ...
- DWZ (JUI) 教程 tree 控件的选中事件
DWZ (JUI) 教程 tree 控件的选中事件 先简单说一下流程 第一步 当然是先定义好回调事件了 function checkCallback(json){ ........... ...... ...
- rs.open 打开数据库权限问题 rs.open sql,conn,1,3 等后缀权限问题
Rs.open sql,conn,[0~3],[1~4] 这两个是游标,具体的作用是:RS.OPEN SQL,CONN,A,BA:ADOPENFORWARDONLY(=0)只读,且当前数据记录只能向下 ...
- swift 闭包简写实际参数名$0、$1等理解
Swift 自动对行内闭包提供简写实际参数名,你也可以通过 $0 , $1 , $2 等名字来引用闭包的实际参数值. 如果你在闭包表达式中使用这些简写实际参数名,那么你可以在闭包的实际参数列表中忽略对 ...
- UI2_UITableViewDelete
// AppDelegate.m // UI2_UITableViewDelete // // Created by zhangxueming on 15/7/14. // Copyright (c) ...
- UI3_UIView自动布局
// // ViewController.m // UI3_UIView自动布局 // // Created by zhangxueming on 15/7/1. // Copyright (c) 2 ...
- Spring IoC容器的设计——BeanFactory应用场景2
1.BeanFactory接口设计了getBean方法,这个方法是使用IoC容器API的主要方法,通过这个方法,可以取得IoC容器中管理的Bean,Bean的取得是通过指定名字来索引的. 2.如果需要 ...
- jquery的延迟加载插件Lazy Load Plugin for jQuery
下载:https://github.com/tuupola/jquery_lazyload 使用:http://www.appelsiini.net/projects/lazyload 翻译:http ...
- JQGrid+Webservice+LINQ
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="jqgridtest.asp ...
- js中substring和substr的用法比较
推荐使用substring 方法 stringObject.substring(start,stop) stringObject.substr(start,length) 定义和用法 提取 ...