当前位置:网站首页>PAT甲级 1146 拓扑顺序
PAT甲级 1146 拓扑顺序
2022-07-29 07:01:00 【键盘奏鸣曲】
这是 2018 年研究生入学考试中给出的一个问题:
以下哪个选项不是从给定的有向图中获得的拓扑序列?
现在,请你编写一个程序来测试每个选项。
输入格式
第一行包含两个整数 N 和 M,分别表示有向图的点和边的数量。接下来 M 行,每行给出一条边的起点和终点。
点的编号从 1 到 N。
再一行包含一个整数 K,表示询问次数。
接下来 K 行,每行包含一个所有点的排列。
一行中的数字用空格隔开。
输出格式
在一行中输出所有不是拓扑序列的询问序列的编号。询问序列编号从 0 开始。
行首和行尾不得有多余空格,保证存在至少一个解。
数据范围
1≤N≤1000,
1≤M≤10000,
1≤K≤100
输入样例:
6 8
1 2
1 3
5 2
5 4
2 3
2 6
3 4
6 4
5
1 5 2 3 6 4
5 1 2 6 3 4
5 1 2 3 6 4
5 2 1 6 3 4
1 2 3 4 5 6
输出样例:
3 4
我的解法:
#include <bits/stdc++.h>
using namespace std;
const int N = 1010, M = 10010;
struct Edge{
int a, b;
}e[M];
int p[N];
int n, m;
int main(){
cin >> n >> m;
for(int i = 0; i < m; i ++ ){
cin >> e[i].a >> e[i].b;
}
int k;
cin >> k;
bool is_first = true;
for(int i = 0; i < k; i ++ ){
for(int j = 1; j <= n; j ++ ){
int x;
cin >> x;
p[x] = j;
}
bool success = true;
for(int v = 0; v < m; v ++ ){
if(p[e[v].a] > p[e[v].b]){
success = false;
break;
}
}
if(!success){
if(is_first) is_first = false;
else cout << " ";
cout << i;
}
}
return 0;
}边栏推荐
- Tp6 use protobuf
- Round avatar of user list and follow small blocks
- Leetcode buckle classic problem -- 4. Find the median of two positively ordered arrays
- 2022-07-28: what is the output of the following go language code? A:AA; B:AB; C:BA; D:BB。 package main import ( “fmt“ ) func main() { f
- Win11 system error: code execution cannot continue because ierutil.dll cannot be found. Reinstalling the program may fix this problem
- QT基础第二天(2)qt基础部件:按钮类,布局类,输出类,输入类,容器等个别举例
- Ethernet interface introduction
- Vmware16 create virtual machine: cannot create a new virtual machine, do not have permission to perform this operation
- QT专题:基础部件(按钮类,布局类,输出类,输入类,容器类)
- CAN&CANFD综合测试分析软件LKMaster与PCAN-Explorer 6分析软件的优势对比
猜你喜欢
![[Charles' daily problems] when you open Charles, you can't use nails](/img/ef/037fc416175d4de769ac6484cb53df.png)
[Charles' daily problems] when you open Charles, you can't use nails

It's enough for MySQL to have this article (disgusting and crazy typing 37k words, just for Bo Jun's praise!!!)

接口测试实战项目03:执行测试用例

Vite3.0 has been released, can you still roll it (list of new features)

Docker最新超详细教程——Docker创建运行MySQL并挂载

作业7.28 文件IO与标准IO

MySQL - multi table query

Remote invocation of microservices

以太网接口介绍

Problems encountered in vmware16 installing virtual machines
随机推荐
20-40k | mecarmand 3D vision algorithm / software / Product Manager Recruitment
[redis] redis development specifications and precautions
Practice of online problem feedback module (XVII): realize the online download function of excel template
Zabbix 其他基础监控项
gcc/g++的使用
Spark Learning Notes (VII) -- spark core core programming - RDD serialization / dependency / persistence / partition / accumulator / broadcast variables
Redis Basics
ERROR 1045 (28000) Access denied for user ‘root‘@‘localhost‘解决方法
BeanUtils.setProperty()
【Unity实战100例】Unity万能答题系统之单选多选判断题全部通用
Excel文件读写(创建与解析)
1-后台项目搭建
Life cycle hooks in routing - activated and deactivated
同步/异步、阻塞/非阻塞 与 IO
H3C_ Using setting default static routing priority to realize the active and standby function of export dual lines
Thinkphp6 realizes database backup
Latest 10 billion quantitative private placement list
mysql 单表最多能存多少数据?
Fillder use
3-global exception handling
