【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, ...
随机推荐
- HDU-3473Minimum Sum
Problem Description You are given N positive integers, denoted as x0, x1 ... xN-1. Then give you som ...
- [Javascript] Object.assign()
Best Pratices for Object.assign: http://www.cnblogs.com/Answer1215/p/5096746.html Object.assign() ca ...
- H.264视频在android手机端的解码与播放(转)
随着无线网络和智能手机的发展,智能手机与人们日常生活联系越来越紧密,娱乐.商务应用.金融应用.交通出行各种功能的软件大批涌现,使得人们的生活丰富多彩.快捷便利,也让它成为人们生活中不可取代的一部分.其 ...
- 通同select便签实现简单的二级联动
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 操作iis
以后研究 try { string method = "Recycle"; string AppPoolName = "z.chinabett.com"; Di ...
- 简易google地图api调用
代码如下: <!DOCTYPE html> <html> <head> <meta name="viewport" content=&qu ...
- MVC使用Exception过滤器自定义处理Action的的异常
1.继承FilterAttribute ,IExceptionFilter自定义处理 /// <summary> /// 登录错误自定义处理 /// </summary> pu ...
- Google2016开发者大会
Android主讲: 一.吴晶:android笔记博主(博客:http://www.race604.com/) 主题:Android低功耗蓝牙(BLE)实践 低功耗蓝牙在可穿戴和智能家居里边用的比较多 ...
- leetcode修炼之路——383. Ransom Note
题目是这样的 Given an arbitrary ransom note string and another string containing letters from a ...
- Oracle Pivot学习心得
今天在做一个查询报表需要将多行的查询结果转换成一行,数据格式如下 ID Type Parameter Value Machine_NO Operator UpdateTime 1 11111111 ...