当前位置:网站首页>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;
}边栏推荐
- 请问flink支持sqlServer数据库么?获取sqlServer数据库的变化
- Gin Middleware
- 论文阅读 (62):Pointer Networks
- Interface test actual project 03: execute test cases
- MySQL uses the client and select methods to view the summary of blob type fields
- Latest 10 billion quantitative private placement list
- 亚马逊云助手小程序来啦!
- 同步/异步、阻塞/非阻塞 与 IO
- 对Vintage分析的一些学习理解
- Spark Learning Notes (VII) -- spark core core programming - RDD serialization / dependency / persistence / partition / accumulator / broadcast variables
猜你喜欢

JS break and continue and return keywords

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

Leetcode buckle classic problem -- 4. Find the median of two positively ordered arrays

MySQL----多表查询

MySQL 使用客户端以及SELECT 方式查看 BLOB 类型字段内容总结

CAN&CANFD综合测试分析软件LKMaster与PCAN-Explorer 6分析软件的优势对比
Scala 高阶(十):Scala中的异常处理

Vmware16 create virtual machine: win11 cannot be installed

JS 鸡生蛋与蛋生鸡问题,Object与Function究竟谁出现的更早?Function算不算Function的实例?

Thinkphp6 realizes database backup
随机推荐
女研究生做“思维导图”与男友吵架!网友:吵架届的“内卷之王”....
Scala 高阶(十):Scala中的异常处理
Section 7 - compilation of programs (preprocessing operations) + links
一篇长文---深入理解synchronized
路由中的生命周期钩子 - activated与deactivated
5-整合swagger2
同步/异步、阻塞/非阻塞 与 IO
logback appender简介说明
QT专题:基础部件(按钮类,布局类,输出类,输入类,容器类)
Round avatar of user list and follow small blocks
CAN&CANFD综合测试分析软件LKMaster与PCAN-Explorer 6分析软件的优势对比
OCR光学字符识别方法汇总
Spark Learning Notes (VII) -- spark core core programming - RDD serialization / dependency / persistence / partition / accumulator / broadcast variables
1 - background project construction
Using C language to skillfully realize the chess game -- Sanzi chess
CVPR2021| 基于自监督学习的多视图立体匹配 (CVPR2021)
[OpenGL] use of shaders
Personal blog system (with source code)
When NPM is installed, it is stuck. There are five solutions
以太网接口介绍
