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的更多相关文章

  1. Codeforces 最大流 费用流

    这套题目做完后,一定要反复的看! 代码经常出现的几个问题: 本机测试超时: 1.init函数忘记写. 2.addedge函数写成add函数. 3.边连错了. 代码TLE: 1.前向星边数组开小. 2. ...

  2. codeforces A. Group of Students 解题报告

    题目链接:http://codeforces.com/problemset/problem/357/A 题目意思:将一堆人分成两组:beginners 和 intermediate coders .每 ...

  3. 图论/暴力 Codeforces Beta Round #94 (Div. 2 Only) B. Students and Shoelaces

    题目传送门 /* 图论/暴力:这是个连通的问题,每一次把所有度数为1的砍掉,把连接的点再砍掉,总之很神奇,不懂:) */ #include <cstdio> #include <cs ...

  4. 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 解 水题,按照题意模拟一下就行了 如果是 ‘ ! ...

  5. 【Codeforces 332C】Students' Revenge

    Codeforces 332 C 我爱对拍,对拍使我快乐... 题意:有\(n\)个议题,学生们会让议会同意\(p\)个,其中主席会执行\(k\)个, 每一个议题执行后主席会掉\(a_i\)的头发,不 ...

  6. 【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 ...

  7. Educational Codeforces Round 76 (Rated for Div. 2) A. Two Rival Students 水题

    A. Two Rival Students There are

  8. 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 ...

  9. [模拟]Codeforces Circle of Students

    Circle of Students time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

随机推荐

  1. DRBD+Heartbeat+Mysql高可用读写分离架构

    声明:本案例仅为评估测试版本 注意:所有服务器之间必须做好时间同步 架构拓扑 IP信息: Heartbeat安装部署 1.安装heartbeat(主备节点同时安装) [root@master1 ~]# ...

  2. C#码农的大数据之路 - HDP SandBox配置及VS连接.md

    在进行HDInsight的开发测试之前,搭建一个测试环境是很重要的. 由于微软与Hortonworks合作开发了HDInsgiht,如果不方便建立Azure账号使用Azure HDInsight进行开 ...

  3. Linux获取UUID

    Linux内核提供有UUID生成接口: cat /proc/sys/kernel/random/uuid Linux上一切皆文件,不管什么程序,读取文件就能获取一个UUID.

  4. bootstrap中的下拉菜单

    下拉菜单必要的代码: <div  class="container"> <div  class="dropdown"> <butt ...

  5. react-router 参数获取

    No BB!!! show me the code. Main.js import { BrowserRouter, Route, Link ,Switch} from 'react-router-d ...

  6. ajax、PHP、session做购物车

    购物车网页代码 1.登录界面login.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ...

  7. iframe访问子页面方法

    在Iframe中调用子页面的Js函数 调用IFRAME子页面的JS函数 说明:假设有2个页面,index.html和inner.html.其中index.html中有一个iframe,这个iframe ...

  8. python网络爬虫之LXML与HTMLParser

    Python lxml包用于解析html和XML文件,个人觉得比beautifulsoup要更灵活些 Lxml中的路径表达式如下: 在下面的表格中,我们已列出了一些路径表达式以及表达式的结果: 路径表 ...

  9. 学习mysql语法--基础篇(一)

      前  言  mysql  mysql语法--本篇学习都是通过使用Navicat Premium(数据库管理工具),连接mysql数据. 本篇学习主要有两个部分:    一.创建用户,创建数据库,给 ...

  10. HTML特殊布局--------双飞翼布局

    今天看到以前写的一篇布局的例子分享给大家,双飞翼布局. 什么是双飞翼布局?? 1.三列布局,中间宽度自适应,两边固定宽度; 2.中间栏在浏览器中优先展示渲染: 双飞翼布局的原理: 中间的盒子定100% ...