本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作。

本文作者:ljh2000
作者博客:http://www.cnblogs.com/ljh2000-jump/
转载请注明出处,侵权必究,保留最终解释权!

题目链接:AGC012B Splatter Painting

正解:逆序暴力

解题报告:

  逆序染色,每次暴力做,每个点记录一下从这个点出发染色的最大的$d$,如果当前的$d<maxd[x]$,那么没必要再往下走下去。

  把没染色的点染上色就好了。

  每个点最多做$10$次。

//It is made by ljh2000
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <string>
#include <queue>
#include <cmath>
#include <ctime>
using namespace std;
typedef long long LL;
const int MAXN = 400011;
const int MAXM = 800011;
int n,m,Q,ecnt,first[MAXN],to[MAXM],nxt[MAXM],col[MAXN],maxd[MAXN];
struct ask{ int x,d,c; }q[MAXN];
inline void link(int x,int y){ nxt[++ecnt]=first[x]; first[x]=ecnt; to[ecnt]=y; }
inline void dfs(int x,int d,int c){
if(!col[x]) col[x]=c; if(maxd[x]>=d) return ;
if(d==0) return ; maxd[x]=d;
for(int i=first[x];i;i=nxt[i]) {
int v=to[i];
dfs(v,d-1,c);
}
} inline void work(){
scanf("%d%d",&n,&m); int x,y;
for(int i=1;i<=m;i++) { scanf("%d%d",&x,&y); link(x,y); link(y,x); }
scanf("%d",&Q); for(int i=1;i<=Q;i++) { scanf("%d%d%d",&q[i].x,&q[i].d,&q[i].c); }
for(int i=Q;i>=1;i--) dfs(q[i].x,q[i].d,q[i].c);
for(int i=1;i<=n;i++) printf("%d\n",col[i]);
} int main()
{
work();
return 0;
}

  

AtCoder Grand Round 012B Splatter Painting的更多相关文章

  1. AtCoder Grand Contest 023 C - Painting Machines

    Description 一个长度为 \(n\) 的序列,初始都为 \(0\),你需要求出一个长度为 \(n-1\) 的排列 \(P\), 按照 \(1\) 到 \(n\) 的顺序,每次把 \(P_i\ ...

  2. AtCoder Grand Contest 012

    AtCoder Grand Contest 012 A - AtCoder Group Contest 翻译 有\(3n\)个人,每一个人有一个强大值(看我的假翻译),每三个人可以分成一组,一组的强大 ...

  3. AtCoder Grand Contest 011

    AtCoder Grand Contest 011 upd:这篇咕了好久,前面几题是三周以前写的... AtCoder Grand Contest 011 A - Airport Bus 翻译 有\( ...

  4. AtCoder Grand Contest 031 简要题解

    AtCoder Grand Contest 031 Atcoder A - Colorful Subsequence description 求\(s\)中本质不同子序列的个数模\(10^9+7\). ...

  5. AtCoder Grand Contest 010

    AtCoder Grand Contest 010 A - Addition 翻译 黑板上写了\(n\)个正整数,每次会擦去两个奇偶性相同的数,然后把他们的和写会到黑板上,问最终能否只剩下一个数. 题 ...

  6. AtCoder Grand Contest 009

    AtCoder Grand Contest 009 A - Multiple Array 翻译 见洛谷 题解 从后往前考虑. #include<iostream> #include< ...

  7. AtCoder Grand Contest 008

    AtCoder Grand Contest 008 A - Simple Calculator 翻译 有一个计算器,上面有一个显示按钮和两个其他的按钮.初始时,计算器上显示的数字是\(x\),现在想把 ...

  8. AtCoder Grand Contest 007

    AtCoder Grand Contest 007 A - Shik and Stone 翻译 见洛谷 题解 傻逼玩意 #include<cstdio> int n,m,tot;char ...

  9. AtCoder Grand Contest 006

    AtCoder Grand Contest 006 吐槽 这套题要改个名字,叫神仙结论题大赛 A - Prefix and Suffix 翻译 给定两个串,求满足前缀是\(S\),后缀是\(T\),并 ...

随机推荐

  1. Elasticsearch提示low disk watermark [85%] exceeded on [UTyrLH40Q9uIzHzX-yMFXg][Sonofelice][/Users/baidu/Documents/work/soft/data/nodes/0] free: 15.2gb[13.4%], replicas will not be assigned to this node

    mac本地启动es之后发现运行一段时间一分钟就能打印好几条info日志: [--13T10::,][INFO ][o.e.c.r.a.DiskThresholdMonitor] [Sonofelice ...

  2. python发送GET或POST请求以便干一些趣事

    适合级别:入门,中级 关键字   :python, http, GET, POST, 安全, 模拟, 浏览器, 验证码,图片识别, google 1 此文不是关于黑客或安全话题的! 2 使用脚本程序发 ...

  3. Purpose of ContextLoaderListener in Spring

    The ApplicationContext is where your Spring beans live. The purpose of the ContextLoaderListener is ...

  4. NodeJS开发环境搭建

    原创作者: zero20121222 NodeJS开发环境搭建 1.安装NodeJS 1.编译环境 源代码编译器,通常 Unix/Linux平台都自带了C++的编译器(GCC/G++).如果没有,请通 ...

  5. GlusterFS部署

    一.GlusterFS简介 PB级容量.高可用.读写性能.基于文件系统级别共享.分布式.无metadata(元数据)的存储方式. GlusterFS(GNU ClusterFile System)是一 ...

  6. APP移动端自动化测试工具选型“兵器谱”一览(主流开源工具)

    (下面大多数工具都是开源工具,在github,码云等开源平台都能找到) "测试那点事儿”在看到360旗下的测试团队整理的关于目前APP移动端自动化相关的工具,觉得总结的很到位,对目前大多数中 ...

  7. k8s-离线安装coreos

    1.安装准备 下载iso 前往页面https://coreos.com/os/docs/latest/booting-with-iso.html 版本:stable 1465.7.0 日期:2017. ...

  8. javascript 闭包 内存

  9. Codeforces Round #112 (Div. 2) D. Beard Graph

    地址:http://codeforces.com/problemset/problem/165/D 题目: D. Beard Graph time limit per test 4 seconds m ...

  10. List泛型集合转DataTable

    自存,此方法可以防止出现DataSet不支持System.Nullable的错误 public static DataTable ToDataTable<T>(IEnumerable< ...