UVa 336 - A Node Too Far
题目大意:在计算机网络中,每条信息都有一个TTL值,在信息到达一个节点时,TTL值首先减1,如果TTL为0,则丢弃该信息报文。给一个网络的配置,给定源点和TTL值,判断该网络中有多少节点不可到达。
无权图(无向)上的单源最短路问题,可用BFS解决。
#include <cstdio>
#include <iostream>
#include <cstring>
#include <map>
#include <queue>
using namespace std;
#define NODEN 35 map<int, int> vertex; void new_vertex(int x)
{
if (!vertex.count(x))
{
int t = vertex.size() + ;
vertex[x] = t;
}
} int main()
{
#ifdef LOCAL
freopen("in", "r", stdin);
#endif
int n, kase = ;
while (scanf("%d", &n) && n)
{
int x, y;
vertex.clear();
vector<int> G[NODEN];
for (int i = ; i < n; i++)
{
scanf("%d%d", &x, &y);
new_vertex(x);
new_vertex(y);
G[vertex[x]].push_back(vertex[y]);
G[vertex[y]].push_back(vertex[x]);
}
int s, ttl, cnt;
int dist[NODEN];
while (scanf("%d%d", &s, &ttl) && (s || ttl))
{
int st = vertex[s];
queue<int> q;
memset(dist, -, sizeof(dist));
dist[st] = ;
q.push(st);
cnt = ;
while (!q.empty())
{
int u = q.front();
q.pop();
for (int i = ; i < G[u].size(); i++)
{
int v = G[u][i];
if (dist[v] != -) continue;
dist[v] = dist[u] + ;
if (dist[v] > ttl) goto s;
q.push(v);
cnt++;
}
}
s: int ans = vertex.size() - cnt;
printf("Case %d: %d nodes not reachable from node %d with TTL = %d.\n", ++kase, ans, s, ttl);
}
}
return ;
}
UVa 336 - A Node Too Far的更多相关文章
- babeljs源码
babel.min.js!function(e,t){"object"==typeof exports&&"object"==typeof mo ...
- Fast Matrix Operations(UVA)11992
UVA 11992 - Fast Matrix Operations 给定一个r*c(r<=20,r*c<=1e6)的矩阵,其元素都是0,现在对其子矩阵进行操作. 1 x1 y1 x2 y ...
- uva 1354 Mobile Computing ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5
- UVA 572 油田连通块-并查集解决
题意:8个方向如果能够连成一块就算是一个连通块,求一共有几个连通块. 分析:网上的题解一般都是dfs,但是今天发现并查集也可以解决,为了方便我自己理解大神的模板,便尝试解这道题目,没想到过了... # ...
- UVA 1151
/* 题意:有n个点,现在需要联通所有,有q种套餐可以选择, 当然套餐之外也可以自己添加边,意为达到最短距离. 题意很明显,不知道需要使用哪一种套餐, 那么需要枚举每一种套餐的情况. 然后再进行对比. ...
- [题解]UVa 11082 Matrix Decompressing
开始眨眼一看怎么也不像是网络流的一道题,再怎么看也觉得像是搜索.不过虽然这道题数据范围很小,但也不至于搜索也是可以随随便便就可以过的.(不过这道题应该是special judge,因为一题可以多解而且 ...
- UVA 12299 RMQ with Shifts(线段树:单点更新)
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- uva 6757 Cup of Cowards(中途相遇法,貌似)
uva 6757 Cup of CowardsCup of Cowards (CoC) is a role playing game that has 5 different characters (M ...
- Node.js的线程和进程
http://www.admin10000.com/document/4196.html 前言 很多Node.js初学者都会有这样的疑惑,Node.js到底是单线程的还是多线程的?通过本章的学习,能够 ...
随机推荐
- 微信小程序Server端环境配置
主要内容:1. SSL免费证书申请步骤2. Nginx HTTPS 配置3. TLS 1.2 升级过程 微信小程序要求使用 https 发送请求,那么Web服务器就要配置成支持 https,需要先申请 ...
- MySQL 建表
SET NAMES utf8; SET FOREIGN_KEY_CHECKS = 0; -- ---------------------------- -- Table structure for ` ...
- Windows查看端口被哪个进程占用
命令 查看PID: netstat -ano|findstr 端口号 查看进程名称: tasklist|findstr PID 结束进程: taskkill -F -PID PID号 配图详解: 1. ...
- php获取Linux网卡信息
$data = exec("/sbin/ifconfig"); var_dump($data); 注意:有时候这种方式获取不到,应该是权限问题 在/var/rootP文件中添加ro ...
- Sichuan State Programming Contest 2012 C。Counting Pair
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=118254#problem/C 其实这道题目不难...就是没有仔细分析... 我们可以发现 ...
- MySQL:MySQL的安装
一.Linux:MySQL的源码安装 1.安装前的准备 在安装之前需要安装一下必备的包和工具 gcc/g++:MySQL5.6开始,需要使用g++进行编译. cmake:MySQL5.5开始,使用cm ...
- bzoj 3879 虚树
题目大意: 给一个字符串,多次询问k个后缀,求它们两两间LCP长度总和 分析: 转化为后缀树,用虚树求 注意: 后缀树中代表后缀的点都是叶子节点 题目中取模并没有卵用 #include <cst ...
- 我的云服务之WWW
云服务器系统是:[root@ip-172-31-27-132 system]# cat /etc/redhat-release Red Hat Enterprise Linux Server rele ...
- MySql绿色版安装过程记录
作为程序猿,要多动手,周末趁着有空且笔记本刚刚装了系统,所以就配置了下绿色版的MySQL. 多动手,多动手,多动手. 多总结,多总结,多总结. 以下为正文: 一.下载MySQL绿色版: 1.这个地址: ...
- JavaScript(二)---- 变量、数据类型和运算符
变量 javaScript中的变量变量是弱类型的,用var来声明. javascript的变量声明格式: var 变量名 = 数据; 声明变量要注意的事项: 1. 在javascript中声明变量是 ...