C - Ilya And The Tree Codeforces Round #430 (Div. 2)
http://codeforces.com/contest/842/problem/C
树 dp
一个数的质因数有限,用set存储,去重
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <time.h>
#include <string>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <ext/rope>
#include <algorithm>
#include <iostream>
using namespace std;
#define ll long long
#define minv 1e-6
#define inf 1e9
#define pi 3.1415926536
#define E 2.7182818284
const ll mod=1e9+;//
const int maxn=2e5+; struct node
{
int d;
node* next;
}*e[maxn]; set<int>y[maxn]; //delete one
int a[maxn],x[maxn],value[maxn];
bool vis[maxn]={}; void dfs(int d)
{
set<int>::iterator i;
int dd; value[d]=x[d];
for (i=y[d].begin();i!=y[d].end();i++)
value[d]=max(value[d],*i); node* p=e[d];
vis[d]=;
while (p)
{
dd=p->d;
if (!vis[dd])
{
x[dd]=__gcd(x[d],a[dd]);
y[dd].insert(x[d]);
for (i=y[d].begin();i!=y[d].end();i++)
y[dd].insert(__gcd(a[dd],*i));
if (d==)
y[dd].insert(a[dd]);
dfs(dd);
}
p=p->next;
}
//free memory
y[d].clear();
} int main()
{
node* p;
int n,X,y,i;
scanf("%d",&n);
for (i=;i<=n;i++)
scanf("%d",&a[i]);
for (i=;i<n;i++)
{
scanf("%d%d",&X,&y);
p=(node*) malloc (sizeof(node));
p->d=y;
p->next=e[X];
e[X]=p; p=(node*) malloc (sizeof(node));
p->d=X;
p->next=e[y];
e[y]=p;
} x[]=a[];
dfs(); for (i=;i<n;i++)
printf("%d ",value[i]);
printf("%d",value[i]);
return ;
}
/*
3
6 10 12
1 2
2 3
*/
C - Ilya And The Tree Codeforces Round #430 (Div. 2)的更多相关文章
- Codeforces Round #430 (Div. 2) C. Ilya And The Tree
地址:http://codeforces.com/contest/842/problem/C 题目: C. Ilya And The Tree time limit per test 2 second ...
- Codeforces Round #430 (Div. 2) 【A、B、C、D题】
[感谢牛老板对D题的指点OTZ] codeforces 842 A. Kirill And The Game[暴力] 给定a的范围[l,r],b的范围[x,y],问是否存在a/b等于k.直接暴力判断即 ...
- Codeforces Round #430 (Div. 2)
A. Kirill And The Game time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- 【Codeforces Round #430 (Div. 2) A C D三个题】
·不论难度,A,C,D自己都有收获! [A. Kirill And The Game] ·全是英文题,述大意: 给出两组区间端点:l,r,x,y和一个k.(都是正整数,保证区间不为空),询问是否 ...
- 【Codeforces Round #430 (Div. 2) C】Ilya And The Tree
[链接]点击打开链接 [题意] 给你一棵n个点的树,每个点的美丽值定义为根节点到这个点的路径上的所有权值的gcd. 现在,假设对于每一个点,在计算美丽值的时候,你可以将某一个点的权值置为0的话. 问你 ...
- D. Vitya and Strange Lesson Codeforces Round #430 (Div. 2)
http://codeforces.com/contest/842/problem/D 树 二进制(路径,每个节点代表一位) #include <cstdio> #include < ...
- A. Ilya and Diplomas( Codeforces Round #311 (Div. 2) )
A. Ilya and Diplomas time limit per test 1 second memory limit per test 256 megabytes input standard ...
- B. Grow The Tree Codeforces Round #594 (Div. 2)
Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on t ...
- Codeforces Round #430 (Div. 2) - D
题目链接:http://codeforces.com/contest/842/problem/D 题意:定义Mex为一个序列中最小的未出现的正整数,给定一个长度为n的序列,然后有m个询问,每个询问给定 ...
随机推荐
- access和MySQL mssql
Access.MSSQL.MYSQL数据库之间有什么区别? Access数据库.MSSQL数据库.MYSQL数据库之间有什么区别? 不少企业和个人站长在网站制作时,会对数据库的概 ...
- 根据 WBS 列新 PID 数据
之前写过关于 菜单树的. http://www.cnblogs.com/newsea/archive/2012/08/01/2618731.html 现在在写城市树. 结构: CREATE TABLE ...
- IE10不能显示JSON文件内容
IE7,8,9下Ajax返回后,再执行跳转,会弹出阻止提示框. 所以我采用WebForm 提交思想: //导出 jv.postOpen = jv.PostOpen = jv.Export = func ...
- mongodb基本使用(四)
MongoDB 条件操作符 描述 条件操作符用于比较两个表达式并从mongoDB集合中获取数据. MongoDB中条件操作符有: (>) 大于 - $gt (<) 小于 - $lt (&g ...
- 投稿007期|令人震惊到发指的PyObject对象代码设计之美
前言 最近在重温经典漫画<SlamDunk>的全国大赛篇,其中的一个情形可以很好的诠释虎躯一震这个状态——当樱木看到流川枫一次高难度投篮时内心的感受:“经过两万次射球练习后,樱木首次明白到 ...
- js给节点添加或删除类名
为 <div> 元素添加 class: document.getElementById(“myDIV”).classList.add(“mystyle”); 为 <div> 元 ...
- 听说 —— beta冲刺总结
听说 -- beta冲刺总结 beta冲刺成员名单 姓名 学号 负责方向 个人主页 周龙荣 031402543 前端页面.跳转 http://www.cnblogs.com/ZHOULR/ 李家鹏 0 ...
- mac下搭建MySql环境基本步骤
准备工作做完后,开始: 创建数据库 step1: 在mac中->系统偏好设置->最下边点MySQL 在弹出页面中 关闭mysql服务(点击stop mysql server) step2: ...
- T4模板_T4基本结构
T4文本模板由 指令块.文本块.控制块 组成. 一. 指令块(MSDN文本模板指令) 指令块以@开头,基本的指令块包括<#@ template #> .<#@ parameter# ...
- Scrum团队 《构建之法》第6~7章
Scrum团队成立 团队名称: 22# 团队目标:做好每次布置的任务 还有提升自己 团队口号:做好现在,展望未来 团队成员:陈楷淇,张裕发,陈泽展,彭一建 角色分配 产品负责人(决定开发内容和优先级排 ...