CSU-1908 The Big Escape
CSU-1908 The Big Escape
Description
There is a tree-like prison. Expect the root node, each node has a prisoner, and the root node is the only exit. Each node can accommodate a large number of prisoners, but each edge per minute only one prisoner can pass.
Now, the big escape begins, every prisoner wants to escape to the exit.Do you know when the last one escapes from the prison.
Input
There are lots of case.
For each test case.The first line contains two integers n,m(n<=100000, 1<=m<=n), which indicates the number of nodes and the root node.
The next n-1 lines describe the tree.
Output
For each test case, you output one line “Case #%d:%d”
Sample Input
10 2
1 2
2 3
2 4
2 5
1 6
5 7
3 8
2 9
2 10
Sample Output
Case #1:2
题解
题意是给定一个树形监狱,每条边每分钟只能允许一个人通过,给定根节点,犯人逃到根节点就算逃出,每个节点可以存在多个犯人,问逃出的最短时间
这个题就是统计根节点最大子树有多少节点
#include<bits/stdc++.h>
#define maxn 100050
using namespace std;
vector<int> G[maxn];
int sum;
void dfs(int u, int fa) {
for (int i = 0; i < G[u].size(); i++) {
int v = G[u][i];
if (v == fa) continue;
sum++;
dfs(v, u);
}
}
int main() {
int n, m;
int cnt = 0;
while (scanf("%d%d", &n, &m) != EOF) {
cnt++;
for (int i = 1; i <= 100000; i++) {
G[i].clear();
}
for (int i = 1; i < n; i++) {
int a, b;
scanf("%d%d", &a, &b);
G[a].push_back(b);
G[b].push_back(a);
}
int ans = 0;
for (int i = 0; i < G[m].size(); i++) {
int v = G[m][i];
sum = 0;
dfs(v, m);
ans = max(ans, sum);
}
printf("Case #%d:%d\n", cnt, ans + 1);
}
}
/**********************************************************************
Problem: 1908
User: Artoriax
Language: C++
Result: AC
Time:748 ms
Memory:8064 kb
**********************************************************************/
CSU-1908 The Big Escape的更多相关文章
- CSU 1556 Jerry's trouble
题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1556 Description Jerry is caught by Tom. He ...
- ACM: Gym 101047E Escape from Ayutthaya - BFS
Gym 101047E Escape from Ayutthaya Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I6 ...
- 简单明了区分escape、encodeURI和encodeURIComponent
一.前言 讲这3个方法区别的文章太多了,但是大部分写的都很绕.本文试图从实践角度去讲这3个方法. 二.escape和它们不是同一类 简单来说,escape是对字符串(string)进行编码(而另外两种 ...
- c#模拟js escape方法
public static string Escape(string s) { StringBuilder sb = new StringBuilder(); byte[] ba = System.T ...
- 【BZOJ-1340】Escape逃跑问题 最小割
1340: [Baltic2007]Escape逃跑问题 Time Limit: 5 Sec Memory Limit: 162 MBSubmit: 264 Solved: 121[Submit] ...
- LYDSY热身赛 escape
Description 给出数字N(1<=N<=10000),X(1<=x<=1000),Y(1<=Y<=1000),代表有N个敌人分布一个X行Y列的矩阵上矩形的行 ...
- javascript escape()函数和unescape()函数
javascript escape()函数和unescape()函数 escape() 函数可对字符串进行编码,这样就可以在所有的计算机上读取该字符串. 语法: escape(string) stri ...
- HDU 3605 Escape(状压+最大流)
Escape Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Sub ...
- escape,encodeURI,encodeURIComponent的区别
escape是对字符串进行编码而另外两种是对URL. encodeURI方法不会对下列字符编码 ASCII字母 数字 ~!@#$&*()=:/,;?+'encodeURIComponent方法 ...
随机推荐
- LAMP stack-5.6.22 (OpenLogic CentOS 7.2)
平台: CentOS 类型: 虚拟机镜像 软件包: apache2.4.20 mysql5.6.30 php5.6.22 apache application server basic softwar ...
- arcgis api for js 地图查询
arcgis api for js入门开发系列四地图查询(含源代码) 上一篇实现了demo的地图工具栏,本篇新增地图查询功能,包括属性查询和空间查询两大块,截图如下: 属性查询效果图: 空间查询效 ...
- window下安装scala搭载Intellij IDE
最近由于公司业务需求,要用到scala,编写还是windows下较好,linux下运行比较靠谱,废话少说,直接上步骤! 1.首先安装java环境 jdk下载地址:http://www.oracle.c ...
- linux 命令——47 iostat (转)
Linux系统中的 iostat 是I/O statistics(输入/输出统计)的缩写,iostat工具将对系统的磁盘操作活动进行监视.它的特点是汇报磁盘活动统计情况,同时也会 汇报出CPU使用情况 ...
- Memory Usage Performance Guidelines
https://developer.apple.com/library/content/documentation/Performance/Conceptual/ManagingMemory/Arti ...
- 【洛谷3950】部落冲突(LCT维护连通性)
点此看题面 大致题意: 给你一棵树,\(3\)种操作:连一条边,删一条边,询问两点是否联通. \(LCT\)维护连通性 有一道类似的题目:[BZOJ2049][SDOI2008] Cave 洞穴勘测. ...
- 使用Scanner类获取键盘输入的会员卡号,并将该数据存储在变量中,输出这个变量的信息
package come.one01;import java.util.Scanner; // 导入Scanner类public class One03 { public static void ma ...
- 操作AD时出现 Access denied error
CommitChanges General Access denied error in Active Directory 1.首先检查AD账户是否具有操作AD的访问权限 2.若用C#类操作AD,还要 ...
- Jmeter压力测试工具基本使用
转:https://blog.csdn.net/envyfan/article/details/42715779
- 【SQL】连接 —— 内连接、外连接、左连接、右连接、交叉连接
连接 · 内连接 · 外连接 · 左连接 · 右连接 · 全连接 · 交叉连接 · 匹配符号(+) 连接 根据表之间的关系,呈现跨表查询的结果. 外连接 内连接 左连接 右连接 全 ...