URAL(timus) 1280 Topological Sorting(模拟)
Topological Sorting
Memory limit: 64 MB
Michael has worked out a study plan for this purpose. But it turned out
that certain subjects may be studied only after others. So, Michael’s
coach analyzed all subjects and prepared a list of M limitations in the form “si ui” (1 ≤ si, ui ≤ N; i = 1, 2, …, M), which means that subject si must be studied before subject ui.
It may appear that it’s impossible to find the correct order of
subjects within the given limitations. In this case any subject order
worked out by Michael is incorrect.
1 ≤ N ≤ 1000; 0 ≤ M ≤ 100000.
Input
Output
a single word “YES” or “NO”. “YES” means that the proposed order is
correct and has no contradictions with the given limitations. “NO” means
that the order is incorrect.
Samples
| input | output |
|---|---|
5 6 |
YES |
5 6 |
NO |
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <time.h>
#include <string>
#include <map>
#include <stack>
#include <vector>
#include <set>
#include <queue>
#define inf 10000000
#define mod 10000
typedef long long ll;
using namespace std;
const int N=;
const int M=;
int power(int a,int b,int c){int ans=;while(b){if(b%==){ans=(ans*a)%c;b--;}b/=;a=a*a%c;}return ans;}
int in[N],vis[N],w[N][N];
int n,m,k;
vector<int>vec[N]; int main()
{
int a,b;
bool flag=true;
scanf("%d%d",&n,&m);
while(m--){
scanf("%d%d",&a,&b);
if(!w[a][b]){
w[a][b]=;
vec[a].push_back(b);
}
}
for(int i=;i<=n;i++){
scanf("%d",&in[i]);
}
for(int i=;i<=n;i++){
int cnt=;
for(int j=i+;j<=n;j++){
if(w[in[i]][in[j]])cnt++;
}
if(cnt!=vec[in[i]].size())flag=false; }
if(flag)printf("YES\n");
else printf("NO\n");
return ;
}
URAL(timus) 1280 Topological Sorting(模拟)的更多相关文章
- hdu.5195.DZY Loves Topological Sorting(topo排序 && 贪心)
DZY Loves Topological Sorting Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 ...
- Lintcode: Topological Sorting
Given an directed graph, a topological order of the graph nodes is defined as follow: For each direc ...
- Topological Sorting
Topological sorting/ ordering is a linear ordering of its vertices such that for every directed edge ...
- Union - Find 、 Adjacency list 、 Topological sorting Template
Find Function Optimization: After Path compression: int find(int x){ return root[x] == x ? x : (root ...
- 拓扑排序(Topological Sorting)
一.什么是拓扑排序 在图论中,拓扑排序(Topological Sorting)是一个有向无环图(DAG, Directed Acyclic Graph)的所有顶点的线性序列.且该序列必须满足下面两个 ...
- Topological Sorting拓扑排序
定义: Topological Sorting is a method of arranging the vertices in a directed acyclic graph (DAG有向无环图) ...
- Course Schedule课程表12(用Topological Sorting)
[抄题]: 现在你总共有 n 门课需要选,记为 0 到 n - 1.一些课程在修之前需要先修另外的一些课程,比如要学习课程 0 你需要先学习课程 1 ,表示为[0,1]给定n门课以及他们的先决条件,判 ...
- hdu 5195 DZY Loves Topological Sorting (拓扑排序+线段树)
DZY Loves Topological Sorting Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 ...
- hdu 5195 DZY Loves Topological Sorting 线段树+拓扑排序
DZY Loves Topological Sorting Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/sho ...
随机推荐
- Rhel7的基本使用
1.修改主机名 [root@localhost ~]# cat /etc/hostname localhost.localdomain[root@localhost ~]# hostnamectl s ...
- iOS程序的启动过程-UIWindow
UIApplicationMain main函数中执行了一个UIApplicationMain这个函数 int UIApplicationMain(int argc, char *argv[], NS ...
- 前端CSS编程之道-LESS
由于前端css编写繁琐,最近开始学习LESS,用LESS编写文件.less文件可以直接编译成我们要的.css文件 学习Less 我下面是我练习时的截图,希望小伙伴也能动手自己写一下,而不是复制粘贴模式 ...
- AS的快捷键
Ctrl+Shift+Alt+N 查找类中的方法或变量 Ctrl+P 方法参数提示 Alt+Insert 生成代码(如get,set方法,构造函数等) 删除导入多余的包Ctrl+Alt+o 提取局部变 ...
- C#基础之程序集(一)
一.什么是程序集? 程序集 其实就是bin目录的.exe 文件或者.dll文件. 二.原理 三.程序集分类 1.系统程序集 路径:C:\Windows\assembly 2.源代码生成的程序集 使用V ...
- 《Java中方法的参数传递方式只有一种:值传递》
//方法的参数传递机制(1):基本类型做形参的传递. class PrimitiveTransferTest { public static void swap(int a,int b) { //下面 ...
- Ubuntu 14.10 下MySQL无法远程连接问题
安装好MySQL之后,如果需要远程连接,那么需要做一些配置,否则会出现一些类似的错误,如 mysql root用户ERROR (): mysql 远程登录 ERROR () mysql 远程登录200 ...
- hdu 2070
ps:...递推..还是给出公式那种... 代码: #include "stdio.h" #define LL long long LL dp[]; int main(){ int ...
- 2016 -1 - 3 省市联动demo
#import "ViewController.h" #import "CZProvinces.h" @interface ViewController ()& ...
- Python网络编程03----Python3.*中socketserver
socketserver(在Python2.*中的是SocketServer模块)是标准库中一个高级别的模块.用于简化网络客户与服务器的实现(在前面使用socket的过程中,我们先设置了socket的 ...