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方法 ...
随机推荐
- RStudio Server-0.99.902 (OpenLogic CentOS 7.2)
RStudio Server-0.99.902 (OpenLogic CentOS 7.2) 0 评论 平台: CentOS 类型: 虚拟机镜像 软件包: r-3.2.3 rstudio-server ...
- 性能调优--大事务与Alwayson 之间的关系
最近性能调优的事比较多,所以摘一些比较有特点的 案例分享下. 业务系统用的是sql server 2016 ,搭建的ALWAYSON 两节点的 群集,今天早上突然辅助 副本的只读库出现大量的等待导致系 ...
- Excel2Dataset
//获取用户打开的Excel文档路径 private stringkkk() { OpenFileDialog selectFile = new OpenFileDialog(); selectFil ...
- 实战:ADFS3.0单点登录系列-集成Exchange
本文将介绍如何将Exchange与ADFS集成,从而实现对于Exchange的SSO. 目录: 实战:ADFS3.0单点登录系列-总览 实战:ADFS3.0单点登录系列-前置准备 实战:ADFS3.0 ...
- 【BZOJ2733】[HNOI2012] 永无乡(启发式合并Splay)
点此看题面 大致题意: 给你一张图,其中每个点有一个权值,有两种操作:在两点之间连一条边,询问一个点所在联通块第\(k\)小的权值. 平衡树 看到第\(k\)小,应该不难想到平衡树. 为了练习\(Sp ...
- 数组使用NSUserDefaults存储的问题,
最近在做搜索记录的时候,由于搜索记录是存储在本地的,而且都是字符串,我考虑到数据量也不是太大,于是就懒的使用数据库了. 于是就想到了NSUserDefaults 存储的方式, 但是由于之间对于数组没有 ...
- 2754: C++习题-快速排序
2754: C++习题-快速排序 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 921 Solved: 406[Submit][Status][Web ...
- final关键字,static关键字
Final final的意思为最终,不可变.final是个修饰符,它可以用来修饰类,类的成员,以及局部变量.不能修饰构造方法. 注意: 被final修饰的类不能被继承但可以继承别的类 class Yy ...
- hello spring boot neo4j
新建springboot 项目: https://www.cnblogs.com/lcplcpjava/p/7406253.html bug fixs: 1. Maven Configuration ...
- 微信小游戏 demo 飞机大战 代码分析(四)(enemy.js, bullet.js, index.js)
微信小游戏 demo 飞机大战 代码分析(四)(enemy.js, bullet.js, index.js) 微信小游戏 demo 飞机大战 代码分析(一)(main.js) 微信小游戏 demo 飞 ...