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 ...
随机推荐
- 【uva 1312】Cricket Field(算法效率--技巧枚举)
题意:一个 L*R 的网格里有 N 棵树,要求找一个最大空正方形并输出其左下角坐标和长.(1≤L,R≤10000, 0≤N≤100) 解法:枚举空正方形也就是枚举空矩阵,先要固定一个边,才好继续操作. ...
- uva10859 Placing Lampposts (树形dp+求两者最小值方法)
题目链接:点击打开链接 题意:给你一个n个点m条边的无向无环图,在尽量少的节点上放灯,使得所有边都被照亮,每盏灯将照亮以它为一个端点的所有边.在灯的总数最小的前提下,被两盏灯同时照亮的边数应尽量大. ...
- 牛客小白月赛30 J.小游戏 (DP)
题意:给你一组数,每次可以选择拿走第\(i\)个数,得到\(a[i]\)的分数,然后对于分数值为\(a[i]-1\)和\(a[i]+1\)的值就会变得不可取,问能得到的最大分数是多少. 题解:\(a[ ...
- 洛谷 P1135 奇怪的电梯 (DFS)
题意:有一\(n\)层高的大楼,每层楼都只能在合法情况下上\(x\)层或者下\(x\)层,问你是否能从\(a\)层楼坐电梯到\(b\)层楼,输出最小步数. 题解:直接dfs搜,\(flo\)表示层数, ...
- 数据库之postgreSQL入门操作指南
一.增 二.删 三.改 四.查 五.SQL操作表 1.增加列 ALTER TABLE table_name ADD column_name datatype; 2.删除一列 ALTER TABLE t ...
- TCP之“3次握手,4次挥手”问题
你知道"3次握手,4次挥手"吗? 当面试官问你什么是"3次握手,4次挥手",你是不是要开启"诵经"模式了?作为程序员,要有"刨根问 ...
- 手把手搭建一套私有 npm 服务
手把手搭建一套私有 npm 服务 gnpm xnpm pnpm lnpm refs xgqfrms 2012-2020 www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
- LeetCode Binary Search All In One
LeetCode Binary Search All In One Binary Search 二分查找算法 https://leetcode-cn.com/problems/binary-searc ...
- TypeScript 面试题汇总(2020 版)
TypeScript 面试题汇总(2020 版) TypeScript 3.9 https://www.typescriptlang.org/zh/ TypeScript 4.0 RC https:/ ...
- redux & connect
redux & connect import React, { Component, // useState, // useEffect, } from 'react'; import { b ...