HUST 1103 校赛 邻接表-拓扑排序
Description
Input
Output
Sample Input
2
3
1 2
1 3
1 1
3
1 2
0
1 1
Sample Output
No
Yes
HINT
Student 1 can attend party only if student 2 attend it.
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <utility>
#define MAXX 100010
using namespace std;
const int INF = 0x3f3f3f3f;
pair<vector<int>, int> x;
vector< vector<int> >bel();
queue< vector<int> >qu;
int a[MAXX];
int cnt; int findpush(int n)
{
int flag = ;
for(int i = ; i <= n; i++)
{
if(a[i] == )
{
flag = ;
if(bel[i].size())
qu.push(bel[i]);
else
cnt--;
a[i] = INF;
}
}
return flag;
} int main()
{
int T, n, t, ed;
scanf("%d", &T);
while(T--)
{
scanf("%d",&n);
cnt = n; for(int i = ; i <= n; i++)
a[i] = , bel[i].clear();
for(int i = ; i <= n; i++)
{
scanf("%d", &t);
/* if(!t)
cnt--;*/
while(t--)
{
scanf("%d", &ed);
bel[ed].push_back(i);
a[i]++;
}
}
while(qu.empty())
{
int flag = findpush(n);
if(flag == )
{
if(cnt)
printf("No\n");
else printf("Yes\n");
break;
}
int temp = qu.size();
while(temp--)
{ for(int i = ; i < (qu.front()).size(); i++)
{
a[(qu.front())[i] ]--;
}
qu.pop();
cnt--;
}
}
}
}
HUST 1103 校赛 邻接表-拓扑排序的更多相关文章
- sdut 2819 比赛排名(边表 拓扑排序)
题目:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2819 #include <iost ...
- 2017 ACM-ICPC(乌鲁木齐赛区)网络赛 H.Skiing 拓扑排序+最长路
H.Skiing In this winter holiday, Bob has a plan for skiing at the mountain resort. This ski resort h ...
- NOJ/HUST 1095 校赛 Just Go 线段树模板题
Description There is a river, which contains n stones from left to right. These stones are magic, ea ...
- hdu1285 确定比赛名次(拓扑排序多种方法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1285 Problem Description 有N个比赛队(1<=N<=500),编号依次 ...
- ACM/ICPC 之 数据结构-邻接表+DP+队列+拓扑排序(TSH OJ-旅行商TSP)
做这道题感觉异常激动,因为在下第一次接触拓扑排序啊= =,而且看了看解释,猛然发现此题可以用DP优化,然后一次A掉所有样例,整个人激动坏了,哇咔咔咔咔咔咔咔~ 咔咔~哎呀,笑岔了- -|| 旅行商(T ...
- hdu 2647 (拓扑排序 邻接表建图的模板) Reward
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=2647 老板给员工发工资,每个人的基本工资都是888,然后还有奖金,然后员工之间有矛盾,有的员工希望比某员 ...
- 【数据结构】【图文】【oj习题】 图的拓扑排序(邻接表)
拓扑排序: 按照有向图给出的次序关系,将图中顶点排成一个线性序列,对于有向图中没有限定次序关系的顶点,则可以人为加上任意的次序关系,由此所得顶点的线性序列称之为拓扑有序序列.显然对于有回路的有向图得不 ...
- HDU 4864 Task (贪心+STL多集(二分)+邻接表存储)(杭电多校训练赛第一场1004)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4864 解题报告:有n台机器用来完成m个任务,每个任务有一个难度值和一个需要完成的时间,每台机器有一个可 ...
- HDU 2647 Reward(拓扑排序,vector实现邻接表)
Reward Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
随机推荐
- 福大软工1816:beta版本冲刺前准备
BETA 版冲刺前准备 队名:第三视角 作业链接 组长博客 应作业要求为了更加顺利地开展beta版本的冲刺,上次的alpha版本展示后,我们组对之前开发过程中存在的各种问题进行了全面的讨论,并对其进行 ...
- 【IdentityServer4文档】- 支持和咨询选项
支持和咨询选项 我们为 IdentityServer 提供多个免费和商业支持及咨询选项. 免费支持 免费支持是基于社区的,而且使用的是公共论坛 StackOverflow 有越来越多的使用 Ident ...
- scrapy(1)——scrapy介绍
Scrapy是一个为了爬取网站数据,提取结构性数据而编写的应用框架. 可以应用在包括数据挖掘,信息处理或存储历史数据等一系列的程序中.所谓网络爬虫,就是一个在网上到处或定向抓取数据的程序,当然,这种说 ...
- sublime Remote_encoding cp1252
"remote_encoding": "cp1252",才能连接远程ftp
- 异常--try..catch
class Program { static void Main(string[] args) { try { object obj = null; int N = (int)obj; } catch ...
- C运行时库
原文地址:http://blog.csdn.net/wqvbjhc/article/details/6612099 在开发window程序是经常会遇到编译好好的程序拿到另一台机器上面无法运行的情况,这 ...
- mysql向上递归&向下递归
工作记录 向上递归函数test: BEGIN ); ); SET sTemp = '$'; SET sTempChd =cast(rid as CHAR); WHILE sTempChd is not ...
- 浅析Docker容器的应用场景
本文来自网易云社区 作者:娄超 过去几年开源界以openstack为代表的云计算持续火了好久,这两年突然又冒出一个叫Docker的容器技术,其发展之迅猛远超预料.网上介绍Docker容器的文章已经很多 ...
- jQuery的动画与特效
显示与隐藏 show() 和 hide() 方法 动画效果的show() 和 hide() show(speed,[]callback) hide(speed,[]callback) speed:表示 ...
- MVC 枚举 转 SelectListItem
ViewBag.userlevel = new SelectList(Enum.GetNames(typeof(AdminLevels)),"", "", te ...