AtCoder Grand Contest 012 B
B - Splatter Painting
Time limit : 2sec / Memory limit : 256MB
Score : 700 points
Problem Statement
Squid loves painting vertices in graphs.
There is a simple undirected graph consisting of N vertices numbered 1 through N, and M edges. Initially, all the vertices are painted in color 0. The i-th edge bidirectionally connects two vertices ai and bi. The length of every edge is 1.
Squid performed Q operations on this graph. In the i-th operation, he repaints all the vertices within a distance of di from vertex vi, in color ci.
Find the color of each vertex after the Q operations.
Constraints
- 1≤N,M,Q≤105
- 1≤ai,bi,vi≤N
- ai≠bi
- 0≤di≤10
- 1≤ci≤105
- di and ci are all integers.
- There are no self-loops or multiple edges in the given graph.
Partial Score
- 200 points will be awarded for passing the testset satisfying 1≤N,M,Q≤2,000.
Input
Input is given from Standard Input in the following format:
N M
a1 b1
:
aM bM
Q
v1 d1 c1
:
vQ dQ cQ
Output
Print the answer in N lines. In the i-th line, print the color of vertex i after the Q operations.
Sample Input 1
7 7
1 2
1 3
1 4
4 5
5 6
5 7
2 3
2
6 1 1
1 2 2
Sample Output 1
2
2
2
2
2
1
0
Initially, each vertex is painted in color 0. In the first operation, vertices 5 and 6 are repainted in color 1. In the second operation, vertices 1, 2, 3, 4 and 5 are repainted in color 2.

Sample Input 2
14 10
1 4
5 7
7 11
4 10
14 7
14 3
6 14
8 11
5 13
8 3
8
8 6 2
9 7 85
6 9 3
6 7 5
10 3 1
12 9 4
9 6 6
8 2 3
Sample Output 2
1
0
3
1
5
5
3
3
6
1
3
4
5
3
The given graph may not be connected.
题意:可以参考图,问你最后的染色情况
解法:因为后面的染色会覆盖前面的,我们就倒过来处理,另外保存每个点的范围
比如1-2-3-4-5-6,
我们从3处理,距离是2
3的处理范围2
2的处理范围1
1的处理范围0
4的处理范围1
5的处理范围0
就是说1,5已经到染色边界了
那么每次染色我们都比较上一次这个点的处理范围,比这一次的大,说明一定会被上一次的覆盖,没必要遍历下去了,或者处理没有染色的部分
#include<bits/stdc++.h>
using namespace std;
#define ll long long
vector<int>q[];
int color[];
int flag[];
int n,m;
int v[],d[],c[];
void dfs(int x,int cnt,int c)
{
if(!color[x])
{
color[x]=c;
}
if(flag[x]>=cnt)
{
return;
}
if(cnt==)
{
return;
}
flag[x]=cnt;
for(int i=;i<q[x].size();i++)
{
dfs(q[x][i],cnt-,c);
}
}
int main()
{
std::ios::sync_with_stdio(false);
cin>>n>>m;
for(int i=;i<=m;i++)
{
int x,y;
cin>>x>>y;
q[x].push_back(y);
q[y].push_back(x);
}
int q;
cin>>q;
for(int i=;i<=q;i++)
{
cin>>v[i]>>d[i]>>c[i];
}
for(int i=q;i>=;i--)
{
dfs(v[i],d[i],c[i]);
}
for(int i=;i<=n;i++)
{
cout<<color[i]<<endl;
}
return ;
}
AtCoder Grand Contest 012 B的更多相关文章
- AtCoder Grand Contest 012
AtCoder Grand Contest 012 A - AtCoder Group Contest 翻译 有\(3n\)个人,每一个人有一个强大值(看我的假翻译),每三个人可以分成一组,一组的强大 ...
- AtCoder Grand Contest 012 A
A - AtCoder Group Contest Time limit : 2sec / Memory limit : 256MB Score : 300 points Problem Statem ...
- AtCoder Grand Contest 012 A - AtCoder Group Contest(贪心)
Time limit : 2sec / Memory limit : 256MB Score : 300 points Problem Statement There are 3N participa ...
- AtCoder Grand Contest 012 C:Tautonym Puzzle
题目传送门:https://agc012.contest.atcoder.jp/tasks/agc012_c 题目翻译 如果一个字符串是好的,那么这个字符串的前半部分和后半部分肯定一模一样.比如\(a ...
- AtCoder Grand Contest 012 D:Colorful Balls
题目传送门:https://agc012.contest.atcoder.jp/tasks/agc012_d 题目翻译 给你一排一共\(N\)个球,每个球有一个颜色\(c_i\)和一个重量\(w_i\ ...
- AtCoder Grand Contest 012 B - Splatter Painting(dp)
Time limit : 2sec / Memory limit : 256MB Score : 700 points Problem Statement Squid loves painting v ...
- AtCoder Grand Contest 012 B Splatter Painting (反向处理 + 记忆化)
题目链接 agc012 Problem B 题意 给定一个$n$个点$m$条边的无向图,现在有$q$个操作.对距离$v$不超过$d$的所有点染色,颜色编号为$c$. 求每个点最后的颜色状态. 倒过 ...
- AtCoder Grand Contest 012 D Colorful Balls
题意: 有N个球排成一行,第i个球颜色为ci, 权为wi, 如果两个同色球权值和 <= X 则它们可以交换: 如果两个异色球权值和 <= Y 则它们可以交换:不限制交换次数,求能到达的颜色 ...
- AtCoder Grand Contest 012 B Splatter Painting(记忆化搜索)
题意: 给一个包含N个顶点,M条边,无自环和重边的简单无向图,初始每个点颜色都为0,每条边的长度为1,连接着ai,bi两个节点.经过若干个操作, 每次将与某个点vi距离不超过di的所有点染成某种颜色c ...
随机推荐
- Arcgis Engine(ae)接口详解(7):地图(map)操作
IMap map = null; //跟map同一层次的activeView对象,他们都是“地图”的对象,map管理地图内容,activeView管理显示内容 IActiveView activeVi ...
- 距特征之k阶距概念
k阶原点距和k阶中心距各是说明什么数字特征 http://www.cnblogs.com/emanlee/archive/2011/04/25/2028628.html 二阶中心距,也叫作方差,它告诉 ...
- POJ 1183 反正切函数的应用(数学代换,基本不等式)
题目链接:http://poj.org/problem?id=1183 这道题关键在于数学式子的推导,由题目有1/a=(1/b+1/c)/(1-1/(b*c))---------->a=(b*c ...
- An O(ND) Difference Algorithm and Its Variations (1986)
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.4.6927 The problems of finding a longest com ...
- HDFS运维和优化
常见问题 下面列举HDFS运行过程中可能出现的常见问题及解决方法,这些问题一般都会在日志中出现的相应的记录.Incompatible clusterIDs in … :namenode cluster ...
- javascript 阻止事件冒泡 cancelBubble
javascript简单的阻止事件冒泡,可以使用事件的cancelBubble方法为true: html部分 <button id="btn1">点击显示div< ...
- Linux下配置rsync服务器
一.简介 rsync是一个远程数据同步工具,可以快速同步多台主机间的文件.Rsync使用所谓的“Rsync算法”来使本地和远程两个主机之间的文件达到同步,这个算法只传送两个文件的不同部分,而不是每次都 ...
- 织梦CMS被挂马特征汇总
一.织梦CMS被挂马特征汇总 2013织梦CMS被挂马特征汇总.最近很多朋友反应后台多了几个系统管理员用户:service.spider等,而且自己之前的管理员用户登陆时候会提示用户名不存在.还有朋友 ...
- CentOS7 安装和配置Tomcat
1.官网下载Tomcat的压缩包 https://tomcat.apache.org/download-70.cgi 2.使用Xftp5把下载的压缩包上传到 /usr/soft (soft文件夹自己新 ...
- codeforces 669E E. Little Artem and Time Machine(节点为map型的线段树)
题目链接: E. Little Artem and Time Machine time limit per test 2 seconds memory limit per test 256 megab ...