当前位置:网站首页>1146 topological order (25 points)
1146 topological order (25 points)
2022-06-29 10:14:00 【Momo 623】
This is a problem given in the Graduate Entrance Exam in 2018: Which of the following is NOT a topological order obtained from the given directed graph? Now you are supposed to write a program to test each of the options.

Input Specification:
Each input file contains one test case. For each case, the first line gives two positive integers N (≤ 1,000), the number of vertices in the graph, and M (≤ 10,000), the number of directed edges. Then M lines follow, each gives the start and the end vertices of an edge. The vertices are numbered from 1 to N. After the graph, there is another positive integer K (≤ 100). Then K lines of query follow, each gives a permutation of all the vertices. All the numbers in a line are separated by a space.
Output Specification:
Print in a line all the indices of queries which correspond to “NOT a topological order”. The indices start from zero. All the numbers are separated by a space, and there must no extra space at the beginning or the end of the line. It is graranteed that there is at least one answer.
Sample Input:
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
Sample Output:
3 4
Give a picture , Then some sequences , Determine whether the sequence is the topological ordering of the whole graph
Judgment method :
- Record each node's read in at the time of input
- When judging the sequence , Place a point in turn x Get out of here y Reduce your penetration by one , That is the x The point is y In front of the point , If it arrives y spot ,y The degree of penetration is still not 0, Explain that it should have been y Click the front point , It must be in y’ After the point .
#include <iostream>
#include <vector>
using namespace std;
const int n = 1e4 + 10;
int N, M, x, y, f;
vector<int> v[n];
int in[n];
int main()
{
cin >> N >> M;
while (M--)
{
cin >> x >> y;
v[x].push_back(y);
// Record the degree of penetration
in[y]++;
}
cin >> M;
for (int i = 0; i < M; i++)
{
// Every time in Will change
vector<int> tin(in, in + N + 1);
int judge = 0;
for (int j = 0; j < N; j++)
{
cin >> x;
if (tin[x])
judge = 1;
for (auto &e : v[x])
tin[e]--;
}
if (judge == 0)
continue;
if (f++ != 0)
cout << " ";
cout << i;
}
return 0;
}
边栏推荐
- 2019icpc上海区域赛赛后总结
- L2-026 小字辈 (25 分)
- 2019.10.23 training summary
- Middle order traversal of Li Kou 94 binary tree
- Alibaba cloud firewall configuration, multiple settings (iptables and firewall)
- L1-009 N个数求和 (20 分)
- 在Activity外使用startActivity()方法报错原因与解决办法
- Dsolve function of sympy
- HDU 6778 Car (分组枚举-->状压 dp)
- 内网穿透工具frp使用入门
猜你喜欢
随机推荐
2019.10.20训练总结
GSOAP example - calc
Codeforces Round #657 Div. 2
Caused by: org. apache. xerces. impl. io. MalformedByteSequenceException: Invalid byte 3 of 3-byte UTF-8
单片机集成开发环境Keil5的使用
Image of the basic component of the shutter
520 钻石争霸赛 2021
JVM之方法返回地址
Alternative implementation of Scrollview pull-down header amplification
完全二叉树的权值 递归做法 ——最后的编程挑战
FreeRTOS (VIII) - time management
FreeRTOS (IX) - queue
XML布局中Button总是在最上层显示
Flutter 基础组件之 Image
内网穿透工具frp使用入门
LiferayPortal JSONWS反序列化漏洞(CVE-2020-7961)分析
Judgment of points inside and outside polygon
2019.10.27 training summary
In XML layout, the button is always displayed on the top layer
2019.11.13训练总结








