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 Round #613 (Div. 2) B. Just Eat It! (DP)
题意:有一个长度为\(n\)的序列,找出最大的长度不为\(n\)的子段和,问最大子段和是否小于所有元素和. 题解:最大子段和我们可以直接用dp来找,每次状态转移为:\(dp[i]=max(dp[i-1 ...
- 【一天一个基础系列】- java之泛型篇
简介 说起各种高级语言,不得不谈泛型,当我们在使用java集合的时候,会发现集合有个缺点:把一个对象"丢进"集合之后,集合就会"忘记"这个对象的数据类型,当再次 ...
- Kubernets二进制安装(16)之安装部署traefik(ingress)
K8S的DNS实现了服务在集群"内"被自动发现,如何使得服务在Kuberneters集群"外"被使用和访问呢,有二种方法 1)使用NodePort型的Servi ...
- 从.NET看微软的焦虑
节日没事,就像聊聊微软的NET. 1.孩子静悄悄,必定在作妖 截止目前,微软的市值达到1.85万亿美元,按说,这样一个宙斯级的巨无霸应该过的非常舒坦, 但是,和微软市值成鲜明的反差,我们从.NET的发 ...
- 读写 LED 作业 台灯的 频闪研究 2 评测&对比!
0. 读写 LED 作业 台灯的 频闪研究 2 评测&对比! 评测&对比图: 1. 日光:(中午12点) 2. Philips: (天猫 15元 5w E27白) 3. FSL: ( ...
- Fullscreen API All In One
Fullscreen API All In One 全屏显示 https://developer.mozilla.org/en-US/docs/Web/API/Fullscreen_API https ...
- C# 6.0 Features , C# 7.0 Features
1 1 1 C# 6.0 Features http://stackoverflow.com/documentation/c%23/24/c-sharp-6-0-features#t=20160828 ...
- Vue & mobile UI components
Vue & mobile UI components https://github.com/vuejs/awesome-vue https://awesome-vue.js.org/ http ...
- vue & vue router & match bug
vue & vue router & match bug match bugs solution name must be router https://stackoverflow.c ...
- The State of JavaScript 2019
The State of JavaScript 2019 https://stateofjs.com/ https://survey.stateofjs.com/ https://2018.state ...