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方法 ...
随机推荐
- Merge更新同步一个表
merge T2 --目标表using T1 --源表 on T1.id=T2.id --匹配条件 when matched then --匹配update set [name]= ...
- POJ 3187 Backward Digit Sums (递推,bruteforce)
第1行j列的一个1加到最后1行满足杨辉三角,可以先推出组合数来 然后next_permutation直接暴. #include<cstdio> #include<iostream&g ...
- vue中created、mounted等方法整理
- Linux学习记录(三)
1.Linux的软件安装 1.1.jdk安装 注意:rpm与软件相关命令 相当于window下的软件助手 管理软件 步骤: 1)查看当前Linux系统是否已经安装java 输入 rpm -qa | g ...
- Oracle 函数 之 wm_concat()
wm_concat() 把列转换成一行一列显示,使用wm_concat函数可以显示在一行一列. --1 建表 create table province_city ( province varchar ...
- java算法面试题:写一个Singleton出来
package com.swift; public class Singleton { public static void main(String[] args) { /* * 写一个Singlet ...
- Python基础-Python注释
一.什么是注释.特性 1.一段文字性的描述,通过注释,可以解释和明确Python代码的功能,并记录将来要修改的地方. 2.当程序处理时,Python解释器会自动忽略,不会被当做代码进行处理 二.注释的 ...
- 【前端_js】理解 JavaScript 的 async/await
async 和 await 在干什么 任意一个名称都是有意义的,先从字面意思来理解.async 是“异步”的简写,而 await 可以认为是 async wait 的简写.所以应该很好理解 async ...
- 第2 章Python 语言基础
必背必记 1.转义字符 Python 中的字符串还支持转义字符.所谓转义字符是指使用反斜杠“\”对一些特殊字符进行转义. \ 续行符 \n 换行符 \0 空 \t 水平制表符,用于横向跳到下一制表 ...
- Net core 轮子
.net core 使用的人渐渐多了起来,轮子也渐渐多了起来,为了避免重复造轮子,以下列举了一些造好的轮子 1. IP 请求频率限制 git: https://github.com/stefanpro ...