Legal or Not HDU - 3342 (拓扑排序)


注意点: 输入数据中可能有重复,需要进行处理!
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <sstream> using namespace std; int n, m; int indegree[];
int g[][]; int main()
{
while(scanf("%d %d", &n, &m) != EOF)
{
if(n == && m == )
break; memset(indegree, , sizeof(indegree));
memset(g, , sizeof(g)); int a, b;
for(int i = ; i <= m; ++i)
{
scanf("%d %d", &a, &b); if(g[a][b] == ) // 输入中有可能有反复输入如1,2;1,2这种情况!!!
{
g[a][b] = ;
indegree[b]++;
} } int cnt = ; for(int k = ; k < n; ++k)
{
int i, j;
for(i = ; i < n; ++i)
{
if(indegree[i] == )
{
indegree[i] = -;
cnt++;
break;
}
} for(j = ; j < n; ++j)
{
if(g[i][j] == )
{
indegree[j]--;
g[i][j] == ;
}
}
} if(cnt == n)
cout << "YES" << endl;
else
cout << "NO" << endl;
} return ;
}
Legal or Not HDU - 3342 (拓扑排序)的更多相关文章
- hdu 3342 拓扑排序 水
好久没切题 先上水题! 拓扑排序! 代码: #include<iostream> #include<cstdio> #include<cstring> using ...
- HDU 3342 拓扑排序模板
Legal or Not Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- HDU 4857 拓扑排序 优先队列
n个数,已经有大小关系,现给m个约束,规定a在b之前,剩下的数要尽可能往前移.输出序列 大小关系显然使用拓扑结构,关键在于n个数本身就有大小关系,那么考虑反向建图,优先选择值最大的入度为零的点,这样得 ...
- HDU 1811 拓扑排序 并查集
有n个成绩,给出m个分数间的相对大小关系,问是否合法,矛盾,不完全,其中即矛盾即不完全输出矛盾的. 相对大小的关系可以看成是一个指向的条件,如此一来很容易想到拓扑模型进行拓扑排序,每次检查当前入度为0 ...
- HDU 3342 Legal or Not (最短路 拓扑排序?)
Legal or Not Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- HDU 3342 -- Legal or Not【裸拓扑排序 &&水题 && 邻接表实现】
Legal or Not Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...
- HDU 5638 拓扑排序+优先队列
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5638 题意: 给你一个DAG图,删除k条边,使得能个得到字典序尽可能小的拓扑排序 题解: 把拓扑排序 ...
- hdu 2647 (拓扑排序 邻接表建图的模板) Reward
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=2647 老板给员工发工资,每个人的基本工资都是888,然后还有奖金,然后员工之间有矛盾,有的员工希望比某员 ...
- 传递 hdu 5961 拓扑排序有无环~
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5961 题目为中文,这里就不描述题意了. 思路: 从题目陈述来看,他将一个有向图用一个邻接矩阵来表示,并且分 ...
随机推荐
- SDOI2019 R2退役记
还是退役了呀 Day -1 早上loli发了套题结果啥都不会 之后胡爷爷就秒了道数据结构 不过也没什么人做,于是全机房都在愉快的划水 下午来机房打了场luogu的\(rated\)赛,还是啥都不会 之 ...
- PKUWC&SC 2018 刷题记录
PKUWC&SC 2018 刷题记录 minimax 线段树合并的题,似乎并不依赖于二叉树. 之前写的草率的题解在这里:PKUWC2018 minimax Slay the Spire 注意到 ...
- 枚举进程,线程,堆 CreateToolhelp32Snapshot
Takes a snapshot of the processes and the heaps, modules, and threads used by the processes.对当前系统进行一 ...
- day19 作业
今日作业 1.什么是对象?什么是类? 对象:特征和技能的结合体 类:一系列对象 相同的特征和技能的结合体 2.绑定方法的有什么特点 对象调用类内部的函数 称之为绑定方法,特点: 不同的对象调用该绑定方 ...
- RN 开发工具及发布release版本
2.1.开发工具推荐visual studio code https://code.visualstudio.com/docs/?dv=win 选择安装react native tool 就可以了 2 ...
- PAT甲级——A1055 The World's Richest
Forbes magazine publishes every year its list of billionaires based on the annual ranking of the wor ...
- SpringBoot防XSS攻击
1 . pom中增加依赖 <!-- xss过滤组件 --> <dependency> <groupId>org.jsoup</groupId> < ...
- Java中移动文件或目录的方法盘点
本文不再更新,可能存在内容过时的情况,实时更新请移步原文地址:Java中移动文件或目录的方法盘点: import org.apache.commons.io.FileUtils; import jav ...
- spotbus gradle-qulity-plugiin 多项目bug检查
https://spotbugs.readthedocs.io/en/latest/bugDescriptions.html https://xvik.github.io/gradle-quality ...
- [Array]1. Two Sum(map和unorder_map)
Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...