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. [2017 ACL] 对话系统

    Long Papers [Domain adaptation ] 1. Adversarial Adaptation of Synthetic or Stale Data ( Cited by 14 ...

  2. lscpi命令详解

    基础命令学习目录 lspci是一个用来查看系统中所有PCI总线以及连接到该总线上的设备的工具. 命令格式为 lspci -参数 (不加参数显示所有硬件设备) 至于有哪些参数及其详细用法可以看下这篇博客 ...

  3. [linux] 查看网卡UUID

    virtualbox复制了虚拟机,重新初始化网卡后,需要对/etc/sysconfig/network-scripts/ifcfg-eth0更新UUID值,虽然不改暂时也没发现有问题. 网上查找需要n ...

  4. 前端_CSS

    目录 CSS语法 CSS的四种引入方式 CSS选择器 CSS属性操作 补充 示例(一些小模板) CSS语法 CSS 规则由两个主要的部分构成:选择器,以及一条或多条声明. 1 2 3 4 5 6 7 ...

  5. 【转】git乱码解决方案汇总

    git乱码解决方案汇 2012-11-04更新:官方的“终极”解决方案:msysGit1.7.10开始使用UTF-8编码保存文件名. 2011-10-24更新: 从一篇链接到本篇文章的文章(我对这篇文 ...

  6. Java第一次试验

    北京电子科技学院(BESTI) 实     验    报     告 课程:Java程序设计   班级:1352       姓名:朱国庆   学号:20135237 成绩:             ...

  7. 2018-2019-20172329 《Java软件结构与数据结构》第八周学习总结

    2018-2019-20172329 <Java软件结构与数据结构>第八周学习总结 现在对于我而言,最珍贵的是时间,感觉自己在时间飞逝的时候真的挽留不住什么,只能怒发冲冠的让自己疯狂的学习 ...

  8. Gogoing 场景调研(补)

    一.典型用户 蜗居在学校的大学生 二.场景描述 编号 用户故事 故事价值 (点数) 1 作为一名大学生,只知道学习 2 经常打游戏而无所事事的大学生 1.背景 (1)典型用户:张晨建 (2)用户的需求 ...

  9. Struts2框架学习

    Struts功能详解——ActionMapping对象 ActionMapping描述了struts中用户请求路径和Action的映射关系,在struts中每个ActionMapping都是通过pat ...

  10. Failed to execute request because the App-Domain could not be created. Error: 0x8007000e 存储空间不足,无法完成此操作。

    今天业务发现,服务器上的网站无法访问了. 页面报错: Server Application UnavailableThe web application you are attempting to a ...