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 ...
随机推荐
- CentOS挂载优盘
插入优盘前: [root@centOS5 mnt]# fdisk -l Disk /dev/hdd: bytes heads, sectors/track, cylinders Units = cyl ...
- Entity Framework 6 Code First 实践系列(1):实体类配置-根据依赖配置关系和关联
EF实体类的配置可以使用数据注释或Fluent API两种方式配置,Fluent API配置的关键在于搞清实体类的依赖关系,按此方法配置,快速高效合理.为了方便理解,我们使用简化的实体A和B以及A.B ...
- 文件宝局域网传输/播放功能使用帮助(Mac电脑用户)
使用局域网账户密码登录,可以访问电脑上所有文件 使用游客无账户密码登录,只能访问电脑上指定共享文件夹的文件. 怎么设置共享文件夹请参考: 1.打开“共享”偏好设置(选取苹果菜单 >“系统偏好设置 ...
- compile java sources
Information:javac 1.8.0_91 was used to compile java sources D:\myjdk\bin\java "-javaagent:C:\Pr ...
- CLI和CGI的区别
CGI :“公共网关接口”(Common Gateway Interface),HTTP服务器与你的或其它机器上的程序进行“交谈”的一种工具,其程序须运行在网络服务器上.以CGI方式运行时,web s ...
- mysql----其他小技巧
小技巧: min/max优化 在表中,一般都是经过优化的. 如下地区表 id area pid 1 中国 0 2 北京 1 ... 3115 3113 我们查min(id), id是主键,查Min(i ...
- Your Firefox profile cannot be loaded. It may be missing or inaccessible
ubuntu下出现打开frefox出现Your Firefox profile cannot be loaded. It may be missing or inaccessible 1:用命令行输入 ...
- poj 1195 Mobile phones 解题报告
题目链接:http://poj.org/problem?id=1195 题目意思:有一部 mobie phone 基站,它的面积被分成一个个小正方形(1 * 1 的大小),所有的小正方形的面积构成了一 ...
- java的数字精确计算问题-BigDecimal
java的数字运算,偶尔会出现精度的问题,以下阐述的 java的BigDecimal类的使用. 例如: System.out.println(0.9+0.3); 结果1.2 System.out.pr ...
- 为datanode配置多个数据存储地
datanode配置多个数据存储地址,涉及到以下两个配置项 dfs.name.dir Determines where on the local filesystem the DFS name nod ...