【HDOJ】5154 Harry and Magical Computer
拓扑排序。
/* 5154 */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <vector>
using namespace std; #define MAXN 105 vector<int> vec[MAXN];
vector<int>::iterator iter;
int cnt[MAXN];
int n, m; void init() {
int i; memset(cnt, , sizeof(cnt));
for (i=; i<=n; ++i)
vec[i].clear();
} bool topSort() {
int i, j, k, tmp;
int c = ;
queue<int> Q; for (i=; i<=n; ++i) {
if (cnt[i] == ) {
Q.push(i);
}
} while (!Q.empty()) {
++c;
i = Q.front();
Q.pop();
for (iter=vec[i].begin(); iter!=vec[i].end(); ++iter) {
if (--cnt[*iter] == ) {
Q.push(*iter);
}
}
} if (c < n)
return false;
else
return true;
} int main() {
int i, j, k;
bool flag; #ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
#endif while (scanf("%d %d", &n, &m) != EOF) {
init();
for (i=; i<m; ++i) {
scanf("%d %d", &j, &k);
vec[j].push_back(k);
++cnt[k];
}
flag = topSort();
if (flag)
printf("YES\n");
else
printf("NO\n");
} return ;
}
【HDOJ】5154 Harry and Magical Computer的更多相关文章
- hdu 5154 Harry and Magical Computer
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5154 Harry and Magical Computer Description In reward ...
- hdu 5154 Harry and Magical Computer 拓扑排序
Harry and Magical Computer Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- (简单) HDU 5154 Harry and Magical Computer,图论。
Description In reward of being yearly outstanding magic student, Harry gets a magical computer. When ...
- HDU 5154 Harry and Magical Computer bfs
Harry and Magical Computer Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- 【HDOJ】4729 An Easy Problem for Elfness
其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...
- 【HDOJ】【3506】Monkey Party
DP/四边形不等式 裸题环形石子合并…… 拆环为链即可 //HDOJ 3506 #include<cmath> #include<vector> #include<cst ...
- 【HDOJ】【3516】Tree Construction
DP/四边形不等式 这题跟石子合并有点像…… dp[i][j]为将第 i 个点开始的 j 个点合并的最小代价. 易知有 dp[i][j]=min{dp[i][j] , dp[i][k-i+1]+dp[ ...
- 【HDOJ】【3480】Division
DP/四边形不等式 要求将一个可重集S分成M个子集,求子集的极差的平方和最小是多少…… 首先我们先将这N个数排序,容易想到每个自己都对应着这个有序数组中的一段……而不会是互相穿插着= =因为交换一下明 ...
- 【HDOJ】【2829】Lawrence
DP/四边形不等式 做过POJ 1739 邮局那道题后就很容易写出动规方程: dp[i][j]=min{dp[i-1][k]+w[k+1][j]}(表示前 j 个点分成 i 块的最小代价) $w(l, ...
随机推荐
- [连载]JavaScript讲义(03)--- JavaScript面向对象编程
- [AngularJS] ng-if vs ng-show
ng-show: ng-show element will stay in dom, just added a ng-hide attr, so it won't show. ng-if: It ha ...
- 三星笔记本R428安装xp win7双系统,切换系统重启才能进入系统解决办法。
三星笔记本 XP win7 双系统切换重启解决方法 三星笔记本有个奇怪的现象,就是装有XP和win7双系统 xp切换到win7.进系统是会重启一次,并且bios回复光驱为第一启动项,win7切换 ...
- ping and traceroute(tracert)
1.ping程序简单介绍 这个程序是Mike Muuss编写的.目的是測试另外一台机子是否可达. 运用的协议就是ICMP.运用的是ICMP的回显应答和请求回显两个类型.曾经呢.能ping通说明可以进行 ...
- sparkSQL1.1入门之二:sparkSQL执行架构
在介绍sparkSQL之前.我们首先来看看,传统的关系型数据库是怎么执行的.当我们提交了一个非常easy的查询: SELECT a1,a2,a3 FROM tableA Where con ...
- iOS 下的相册与图片处理
需求 很多公司项目中都会使用到相册,以及相机,保存图片,从相册中选取图片等等操作.本文将详细介绍该功能如何实现优化,以及使用一些优秀的第三方库来辅助完成我们的需求. photos framework ...
- Day12 - 堡垒机开发
Python之路,Day12 - 那就做个堡垒机吧 本节内容 项目实战:运维堡垒机开发 前景介绍 到目前为止,很多公司对堡垒机依然不太感冒,其实是没有充分认识到堡垒机在IT管理中的重要作用的,很多 ...
- C#中的操作数据库的SQLHelper类
using System; using System.Collections.Generic; using System.Configuration; using System.Data; using ...
- group by、order by 先后顺序问题
今天遇到个小问题 本来是很基础的问题 应该说 基础知道掌握的不牢 好了不说 错误 语句 : select a.a1 from table a where order by a.a1 gro ...
- oracle 自治事物 -- autonomous transaction
一 使用规则 : 在begin 之前申明 : PRAGMA AUTONOMOUS_TRANSACTION; 二 使用理解:autonomous transaction 是一个独立的事务,这一点是理解 ...