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)的更多相关文章

  1. 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 ...

  2. 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.直接暴力判断即 ...

  3. Codeforces Round #430 (Div. 2)

    A. Kirill And The Game time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  4. 【Codeforces Round #430 (Div. 2) A C D三个题】

    ·不论难度,A,C,D自己都有收获! [A. Kirill And The Game] ·全是英文题,述大意:    给出两组区间端点:l,r,x,y和一个k.(都是正整数,保证区间不为空),询问是否 ...

  5. 【Codeforces Round #430 (Div. 2) C】Ilya And The Tree

    [链接]点击打开链接 [题意] 给你一棵n个点的树,每个点的美丽值定义为根节点到这个点的路径上的所有权值的gcd. 现在,假设对于每一个点,在计算美丽值的时候,你可以将某一个点的权值置为0的话. 问你 ...

  6. D. Vitya and Strange Lesson Codeforces Round #430 (Div. 2)

    http://codeforces.com/contest/842/problem/D 树 二进制(路径,每个节点代表一位) #include <cstdio> #include < ...

  7. 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 ...

  8. B. Grow The Tree Codeforces Round #594 (Div. 2)

    Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on t ...

  9. Codeforces Round #430 (Div. 2) - D

    题目链接:http://codeforces.com/contest/842/problem/D 题意:定义Mex为一个序列中最小的未出现的正整数,给定一个长度为n的序列,然后有m个询问,每个询问给定 ...

随机推荐

  1. Inception——Going deeper with convolutions

    1. 摘要 作者提出了一个代号为 Inception 的卷积神经网络架构,这也是作者在 2014 年 ImageNet 大规模视觉识别挑战赛中用于分类和检测的新技术. 通过精心的设计,该架构提高了网络 ...

  2. python常用模块目录

    博客目录总纲首页 python其他知识目录 random  hashlib  os  sys  json __name__ shutil  xlrd  xlwt   xlutils 核心模块:os s ...

  3. Java将json字符串转成map

    Map<String, Object> map = (Map<String, Object>) JSONUtils.parse(result)

  4. 爱码室Crawler & classification module项目工作分配

    项目情况 爬虫项目是上届学生遗留下来的项目,他们已经实现了基础的功能,而我们来负责完善,主要需要解决的问题是怎么让爬虫脱离爬和停的繁琐指令,更加的智能化.所以我们的计划是在前人的源码基础上,加以修改测 ...

  5. Scrum Meeting 10.31

    成员 今日任务 明日任务 今日工作时长 徐越 整理开发文档,学习ip相关知识,学习servlet相关知识 代码迁移,学习数据库相关知识 5h 赵庶宏 学习学长的servlet代码 进行数据库的连接 4 ...

  6. Servlet 3.0对上传的支持

    Servlet 2.5 进行上传   首先对表单的要求     ->method ="post"    ->enctype="multipart/form-d ...

  7. 软工1816 · 作业(十二)Beta答辩总结

    组长博客 宣传视频 github团队项目仓库 本组成员 队员姓名与学号 124 王彬(组长) 206 赵畅 215 胡展瑞 320 李恒达 131 佘岳昕 431 王源 206 陈文垚 209 陈志炜 ...

  8. HDU 3092 Least common multiple 01背包

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3092 Least common multiple Time Limit: 2000/1000 MS ...

  9. javascript 组件化(转载)

    这边只是很简陋的实现了类的继承机制.如果对类的实现有兴趣可以参考我另一篇文章javascript oo实现 我们看下使用方法: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ...

  10. JPEG标准推荐的亮度、色度DC、AC Huffman编码表

    JPEG 标准推荐的亮度.色度DC.AC Huffman 编码表 博主在完成数字图像处理大作业时利用搜索引擎查找了很久完整的四张Huffman 编码表(亮度AC Huffman编码表.亮度DC Huf ...