codeforces 129B students and shoes
https://vjudge.net/problem/CodeForces-129B
题意:
有n个学生,他们之间被鞋带缠住了。现在,老师首先把所有只与一个学生直接相连的学生找出来,让他们聚集到一起,然后把他们踢出去,直到无人可踢为止。问可以踢多少次。
思路:
用拓扑排序的思路,从所有点的度数下手。将所有度数为1的点入队,之后把他们连接的点的度数全部减一,自己也减1,之后再把所有的度数为1的点入队,循环,直到队列为空。
代码:
#include <stdio.h>
#include <string.h>
#include <queue>
#include <vector>
using namespace std; int d[]; queue<int> q;
vector<int> v[]; int main()
{
int n,m; scanf("%d%d",&n,&m); for (int i = ;i < m;i++)
{
int a,b; scanf("%d%d",&a,&b); d[a]++;d[b]++; v[a].push_back(b);
v[b].push_back(a);
} for (int i = ;i <= n;i++)
{
if (d[i] == ) q.push(i);
} int ans = ; while (!q.empty())
{
int cnt = ; int b[]; while (!q.empty())
{
b[cnt++] = q.front();q.pop();
} if (cnt > ) ans++; for (int i = ;i < cnt;i++)
{
int t = b[i];
d[t]--; for (int j = ;j < v[t].size();j++)
{
int s = v[t][j]; if (d[s] >= )
{
d[s]--;
}
}
} for (int i = ;i <= n;i++)
{
if (d[i] == ) q.push(i);
}
} printf("%d\n",ans); return ;
}
codeforces 129B students and shoes的更多相关文章
- Codeforces 最大流 费用流
这套题目做完后,一定要反复的看! 代码经常出现的几个问题: 本机测试超时: 1.init函数忘记写. 2.addedge函数写成add函数. 3.边连错了. 代码TLE: 1.前向星边数组开小. 2. ...
- codeforces A. Group of Students 解题报告
题目链接:http://codeforces.com/problemset/problem/357/A 题目意思:将一堆人分成两组:beginners 和 intermediate coders .每 ...
- 图论/暴力 Codeforces Beta Round #94 (Div. 2 Only) B. Students and Shoelaces
题目传送门 /* 图论/暴力:这是个连通的问题,每一次把所有度数为1的砍掉,把连接的点再砍掉,总之很神奇,不懂:) */ #include <cstdio> #include <cs ...
- Codeforces Round #454 Div. 1 [ 906A A. Shockers ] [ 906B B. Seating of Students ] [ 906C C. Party ]
PROBLEM A. Shockers 题 http://codeforces.com/contest/906/problem/A 906A 907C 解 水题,按照题意模拟一下就行了 如果是 ‘ ! ...
- 【Codeforces 332C】Students' Revenge
Codeforces 332 C 我爱对拍,对拍使我快乐... 题意:有\(n\)个议题,学生们会让议会同意\(p\)个,其中主席会执行\(k\)个, 每一个议题执行后主席会掉\(a_i\)的头发,不 ...
- 【CodeForces 129 B】Students and Shoelaces(拓扑排序)
Anna and Maria are in charge of the math club for junior students. When the club gathers together, t ...
- Educational Codeforces Round 76 (Rated for Div. 2) A. Two Rival Students 水题
A. Two Rival Students There are
- Educational Codeforces Round 76 (Rated for Div. 2) A. Two Rival Students
You are the gym teacher in the school. There are nn students in the row. And there are two rivalling ...
- [模拟]Codeforces Circle of Students
Circle of Students time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
随机推荐
- spring.handlers、spring.schemas、spring.tooling被覆盖的三种解决方式
在用到spring时,本地IDE里面跑的很正常,但是打jar包后在集群上运行时报错. 查找资料后确定了问题的根源,由于在依赖中调用了spring的许多包,每个包都有自己的spring.schemas文 ...
- Chrome 开发者工具断点调试(视频教程)
很多人不了解 Chrome Dev Tools (开发者工具)的使用方法和技巧. 其中很多技能,无论是前端开发从业者,还是普通用户,了解一些还是对日常很有帮助的. 本猿定期录制.甚至根据您的需求来订制 ...
- boost.property_tree读取中文乱码问题正确的解决方式
开发项目的时候在使用boost,在宽字符下遇到中文乱码问题 上网上看大家都是先转成utf8在进行解析的,例如: http://blog.csdn.net/hu_jiangan/article/deta ...
- Android搞事篇——使用Intent跳转界面
跳转页面基本分为三个步骤: 1.初始化一个intent:(一个intent就够用了): 2.传入intent参数: 3.调用startactivity();实现跳转页面 具体操作如下 首先你需要一个项 ...
- jquery页面水印插件,支持多行水印、行错开
最近工作需求,需要在页面上加水印,但发现网上示例无法满足我的需求,所以还是自己动手写. 有几个特别需求: 1.可以写多行水印,并且中心对齐. 2.每行水印错开. PS:我找到的例子都是单行水印,所以用 ...
- mysql之 mysql 5.6不停机主主搭建(活跃双主基于日志点复制)
环境说明:版本 version 5.6.25-log 主库ip: 10.219.24.25从库ip:10.219.24.22os 版本: centos 6.7已安装热备软件:xtrabackup 防火 ...
- Spring学习(24)--- AOP之 Aspect instantiation models(aspect实例模式)特别说明
重要: schema-defined aspects只支持singleton model,即 基于配置文件的aspects只支持单例模式
- 安装并配置Apache
从今天开始,我将开始Web开发的学习.本系列博客将陆续记录我学习过程中的收获和困惑,从前端到后端,一探Web开发的流程和内容.我目前掌握的有C/C++,有一些使用C进行嵌入式开发的经验,C++就马马虎 ...
- React + Redux + express+ antd 架构的认识
在过去的两周里,我使用这套技术栈进行项目页面的开发.下面是我个人的对于项目的一些看法: 首先:是项目的调试,我深表压力很大,项目是使用fibber去抓包调试的,也不知道我们项目的负责人,怎么能的我在每 ...
- go 测试sort性能
package main import "fmt" import "os" import "flag" import "bufio ...