PAT-1146(Topological Order)拓扑排序+判断一个序列是否满足拓扑序列
Topological Order
PAT-1146
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cstdio>
#include<sstream>
#include<set>
#include<map>
#include<cmath>
#include<vector>
#include<unordered_map>
using namespace std;
int n,m;
const int maxn=1003;
const int maxm=10004;
int ma[maxn][maxn];
int temp[maxn];
int main(){
	cin>>n>>m;
	memset(ma,-1,sizeof(ma));
	for(int i=0;i<m;i++){
		int from,to;
		cin>>from>>to;
		ma[from][to]=1;
		ma[from][from]=0;
		ma[to][to]=0;
	}
	int k;
	cin>>k;
	vector<int>ve;
	for(int i=0;i<k;i++){
		for(int j=0;j<n;j++){
			cin>>temp[j];
		}
		bool flag=true;
		for(int j=0;j<n;j++){
			for(int t=0;t<j;t++){
				if(ma[temp[j]][temp[t]]==1){
					flag=false;
					break;
				}
			}
			if(!flag)
				break;
		}
		if(!flag){
			ve.push_back(i);
		}
	}
	for(int i=0;i<ve.size();i++){
		if(i==(int)ve.size()-1){
			cout<<ve[i]<<endl;
		}else{
			cout<<ve[i]<<" ";
		}
	}
	return 0;
}
												
											PAT-1146(Topological Order)拓扑排序+判断一个序列是否满足拓扑序列的更多相关文章
- PAT 1146 Topological Order[难]
		
1146 Topological Order (25 分) This is a problem given in the Graduate Entrance Exam in 2018: Which o ...
 - [PAT] 1146 Topological Order(25 分)
		
This is a problem given in the Graduate Entrance Exam in 2018: Which of the following is NOT a topol ...
 - PAT 1146 Topological Order
		
This is a problem given in the Graduate Entrance Exam in 2018: Which of the following is NOT a topol ...
 - PAT 甲级 1146 Topological Order (25 分)(拓扑较简单,保存入度数和出度的节点即可)
		
1146 Topological Order (25 分) This is a problem given in the Graduate Entrance Exam in 2018: Which ...
 - hdoj 4324 Triangle LOVE【拓扑排序判断是否存在环】
		
Triangle LOVE Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tot ...
 - 拓扑排序  判断给定图是否存在合法拓扑序列 自家oj1393
		
//拓扑排序判断是否有环 #include<cstdio> #include<algorithm> #include<string.h> #include<m ...
 - PAT A1146 Topological Order (25 分)——拓扑排序,入度
		
This is a problem given in the Graduate Entrance Exam in 2018: Which of the following is NOT a topol ...
 - PAT甲级——1146 Topological Order (25分)
		
This is a problem given in the Graduate Entrance Exam in 2018: Which of the following is NOT a topol ...
 - PAT 甲级 1146 Topological Order
		
https://pintia.cn/problem-sets/994805342720868352/problems/994805343043829760 This is a problem give ...
 
随机推荐
- CodeForces 1119D(差分+前缀和+二分)
			
题意:给你一个数组,数组每次每个数都+1,有q次查询每一查询+L到+R中出现的所有不重复的数字个数. +L到+R其实就相当于是0到+(R-L+1) 感觉自己写的好啰嗦,直接上代码加注释: 1 #inc ...
 - c语言实现--带头结点单链表操作
			
可能是顺序表研究的细致了一点,单链表操作一下子就实现了.这里先实现带头结点的单链表操作. 大概有以下知识点. 1;结点:结点就是单链表中研究的数据元素,结点中存储数据的部分称为数据域,存储直接后继地址 ...
 - poj3087 Shuffle'm Up
			
Description A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuff ...
 - hdu5305 Friends
			
Problem Description There are n people and m pairs of friends. For every pair of friends, they can c ...
 - nuoyanli 520 Let‘s play computer game
			
H题 描述 xxxxxxxxx在疫情期间迷上了一款游戏,这个游戏一共有nnn个地点(编号为1--n1--n1--n),他每次从一个地点移动到另外一个地点需要消耗 一定的能量,每一个地点都有一些珠宝,输 ...
 - JavaScript——原型
			
原型中的原先设定的值不能改变!!!
 - LINUX - 随机数
			
#include <stdio.h> #include <stdlib.h> #include <pthread.h> #include <unistd.h& ...
 - C++ part6
			
C++源文件从文本到可执行文件经历的过程 references: 一个C++源文件从文本到可执行文件经历的过程 C++源文件从文本到可执行文件经历的过程 gcc程序编译的静态链接和动态链接 保留中间过 ...
 - bzoj4695 最假女选手(势能线段树/吉司机线段树)题解
			
题意: 已知\(n\)个数字,进行以下操作: \(1.\)给一个区间\([L,R]\) 加上一个数\(x\) \(2.\)把一个区间\([L,R]\) 里小于\(x\) 的数变成\(x\) \(3.\ ...
 - 钉钉 & URL Scheme & Universal Link & Deep Link
			
钉钉 & URL Scheme & Universal Link & Deep Link DD link https://www.cnblogs.com/xgqfrms/p/1 ...