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个询问,每个询问给定 ...
随机推荐
- 深度学习中数据的augmentation
为了提高模型的泛化能力,同时也为了增大数据集,我们往往需要对数据进行augmentation,在这篇博客中,将总结一下可以对数据进行的augmentation. 1.颜色数据增强,对图像亮度.饱和度. ...
- 笨办法学Python - 习题4: Variables and Names
1.习题 4: 变量(variable)和命名 学习目标:了解Python中变量的定义,学习定义简明易记的变量名 变量:变量是存储内存中的值,就是每定义一个变量就会在内存中开辟一个空间.基于变量的类型 ...
- redis解决商品秒杀问题
博主最近在项目中遇到了抢购问题!现在分享下.抢购.秒杀是如今很常见的一个应用场景,主要需要解决的问题有两个:1 高并发对数据库产生的压力2 竞争状态下如何解决库存的正确减少("超卖" ...
- 在 Linux 下执行安装 bin 文件
原文: http://www.linuxidc.com/Linux/2014-03/98541.htm
- Dailu Scrum (2015/10/27)
在周日晚上PM已经为大家分配了部分的代码修改工作,今天晚上PM召集了被分配代码工作的3个DEV一起讨论要求修改的代码.在共同讨论的过程中确有发现以下代码的不规范之处,PM当即要求我们先要修改规范代码的 ...
- Ubuntu登录界面添加root用户登录选项
1.普通用户登录系统并打开终端 配置root密码 $sudo passwd 切换至root用户 $su root 输入密码 修改以下配置文件 $nano /usr/share/lightdm/ligh ...
- imooc-c++学习感悟
imooc--慕课网c++课程链接:[课程链接](http://www.imooc.com/course/list?c=C+puls+puls) Imooc 慕课网c++学习感悟 1.课程名称:c++ ...
- 第一次spring冲刺第6天
鉴于昨天的调查,今天做了个谈论,主要针对以下几个问题 1.我们的客户类型? 2.如何实现他们的需求? 3.他们真正想要什么? 4.如何保证他们的满足度? 5.怎么使得工程不陷入死循环? 6.还存在什么 ...
- quartz任务管理
导入quartz相关jar包后,要执行任务的类须实现Job接口 package quartz; import org.quartz.Job; import org.quartz.JobExecutio ...
- 【php】new static的用法
在一个类中,常见的是new self()操作,代表返回自身类的实例. 当父类中存在方法,然后每个子类继承于父类,调用这个方法会返回自身的实例化对象, <?php class A { functi ...