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 ...
随机推荐
- 【noi 2.6_6045】开餐馆(DP)
题意:有N个地址,从中选一些开餐馆,要保证相邻餐馆的距离大于k.问最大利润. 解法:f[i]表示在前 i 个地址中选的最大利润. 1 #include<cstdio> 2 #include ...
- 2019牛客暑期多校训练营(第八场)B Beauty Values && C CDMA
B题题意: 题目 给你n个数,让你把这一个序列中的所有子区间的Beauty Values加起来,Beauty Values是子区间内有几个不同的数 题解: 肯定不会是暴力,所以我们就要在各元素的位置上 ...
- hdu 01 Matrix
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission ...
- 在kubernetes集群里集成Apollo配置中心(1)之交付Apollo-adminservice至Kubernetes集群
1.部署apollo-adminservice软件包 apollo-adminservice软件包链接地址:https://github.com/ctripcorp/apollo/releases/d ...
- InstallShield 2013 Limited Edition for Visual Studio
新建打包项目后,解决方案资源管理器中的结构如下: Project Assistant界面如下: 在Project Assistant中按照步骤创建打包项目: 1.Application Informa ...
- Bootstrap巨幕
这是一个轻量.灵活的组件,它能延伸至整个浏览器视口来展示网站上的关键内容. jumbotron修饰 <div class="jumbotron"> <h1> ...
- 012.NET5_MVC_Razor布局
Razor 页面组成到底有哪些内容? 包含了Layout的母版嵌套的返回需要渲染的视图内容: 如何嵌套? 通过Layout中的RenderBody()方法做了替换,把返回的视图替换到母版页中,形成了一 ...
- JQuery和js实现简单的霓虹灯
注意jquery文件的路径要正确. <!DOCTYPE html> <html> <head> <title></title> <me ...
- Python+OpenCV+图片旋转并用原底色填充新四角
import cv2 from math import fabs, sin, cos, radians import numpy as np from scipy.stats import mode ...
- How to build a sortable table in native js?
How to build a sortable table in native/vanilla js? H5 DnD https://developer.mozilla.org/zh-CN/docs/ ...