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 ...
随机推荐
- Redhat6.x下如何进行远程安装虚拟机
远程主机IP:192.168.122.1 远程主机名:server1.example.com 本地主机IP:192.168.122.2 本地主机名:server2.example.com 1.登录到远 ...
- how to reset mac root password
Reset 10.5 Leopard & 10.6 Snow Leopard password Power on or restart your Mac. At the chime (or g ...
- scrollView自动加载数据demo
package combaidu.mylistsrollview; import java.util.ArrayList;import java.util.List; import com.baidu ...
- 纯JS文本在线HTML编辑器KindEditor
KindEditor(http://www.kindsoft.net)是一款比较专业,主流,好用的在线HTML编辑器. 它除了可以将文本进行编辑.将Word中的内容复制进来外,本身还可以拖动缩放(右下 ...
- swift语言开发的一个游戏------熊猫跑酷(KongfuPanda)
项目地址:https://github.com/jakciehoo/KongfuPanda 欢迎加QQ群:260558552.大家一起交流iOS开发,我们可以一起学习,我很想集结一些志同道合的朋友,一 ...
- sql学习资料
http://blog.sina.com.cn/s/articlelist_1594135432_9_1.html
- jQuery 对dom的操作
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- jQuery easyui 提示框
1:弹出提示窗的使用 (1)屏幕右下弹出提示窗口: $.messager.show({ title:'My Title', msg:'Message will be closed after 4 se ...
- (转)Ratchet教程:创建项目
原文:http://www.w3cplus.com/mobile/how-to-create-mobile-project-width-ratchet.html Ratchet教程:创建项目 ...
- C/C++整数除法以及保留小数位的问题
题目描述 Given two postive integers A and B, please calculate the maximum integer C that C*B≤A, and the ...