Checkpoints(第十一届河南省省赛真题)

Posted Reqaw’s Blog

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Checkpoints(第十一届河南省省赛真题)相关的知识,希望对你有一定的参考价值。

题目描述

As a landlocked country in central and southern Africa , the political situation has been relatively stable since the implementation of multi-party elections in ZBA in 1991. But the ZBA parliament passed the 90 day emergency order issued by the president on 11 days of local time . The tension is that the patriotic team led by the government troops and NPG leaders founded by aborigines started, in addition to the unlawful insurgents of illegal militants.

 

Chinese peacekeepers  are going to the town of Kerver to seek Chinese foreign aid engineers.

The military map shows that there are many checkpoints in the war zone. It can be modeled as a directed graph:  nodes represent checkpoints , and edges represents the roads. The goal is that the less peacekeepers  pass the checkpoints,  the safer it will be.

输入

Input

The first line of the input contains one integer T, which is the number of  test cases (1<=T<=5).  Each test case specifies:

     * Line 1:      N  M  A  B          (2 ≤ N ≤ 100)

N and M  denote the number of nodes and edges in the directed graph respectively. The checkpoints  are labeled 1, 2, ..., N,  where chinese peacekeepers at node A and foreign aid engineers at node B. 

  *Line 2~m+1:  Xi  Yi   (i=1, …., M)

followed by M  lines containing two integers Xi and Yi  (1 ≤ Xi, Yi ≤ N), denoting that there is a directed edge from node Xi to node Yi in the network.

输出

Output

For each test case generate a single line:  a single integer that  the minimum number of checkpoints . If a checkpoint is passed on the way back and forth , it will be counted only once.

样例输入

1
6  10  1  5
1  2
2  1
2  3
3  5
5  4
4  2
1  6
6  5
5  3
3  2

样例输出

2

 1 /*
 2 问题
 3 输入节点数和边数,起点和终点,以及每一条边,计算从起点到终点再返回起点途中最少要经过几个顶点,重复的点不计。
 4 
 5 解题思路
 6 采用Dijkstra算法求一下起点到个点的最短路,然后将走过的点标记一下,再求一下终点到其他点的最短距离,标记过的点
 7 不计算就可以了。 
 8 */ 
 9 #include<cstdio>
10 #include<cstring>
11 int e[110][110],book[110],n,m,ans;
12 void Dijkstra(int s);
13 int main()
14 {
15     int T,u,v,a,b,i,j;
16     scanf("%d",&T);
17     while(T--){
18         scanf("%d%d%d%d",&n,&m,&a,&b);
19         for(i=0;i<n;i++){
20             for(j=0;j<n;j++){
21                 e[i][j] = i==j?0:99999999;
22             }
23         }
24         memset(book,0,sizeof(book));
25         while(m--){
26             scanf("%d%d",&u,&v);
27             e[u][v]=1;
28         }
29         ans=0;
30         Dijkstra(a);
31         Dijkstra(b);
32         printf("%d\n",ans);
33     }
34     return 0;
35 }
36 
37 void Dijkstra(int s)
38 {
39     int dis[110],bk[110]={0},i,j;
40     for(i=0;i<n;i++)
41         dis[i]=e[s][i];
42     
43     dis[s]=0;
44     int u=1;
45     bk[s]=1;
46     for(i=0;i<n;i++){
47         int mina=99999999;
48         for(j=0;j<n;j++){
49             if(bk[j] == 0 && dis[j] < mina){
50                 dis[j]=mina;
51                 u=j;    
52             }
53         }
54         bk[u]=1;
55         if(book[u] == 0)
56             ans++;
57         book[u]=1;
58         for(j=0;j<n;j++){
59             if(bk[j] == 0 && dis[j] < e[u][j]){
60                 dis[j]=e[u][j];
61             }
62         }
63     }
64 }

 

以上是关于Checkpoints(第十一届河南省省赛真题)的主要内容,如果未能解决你的问题,请参考以下文章

河南省第十届ACM省赛赛后感想-想个屁啊!

2020第十一届蓝桥杯真题JAVA B组省赛第二场答案分享(2020.10.17)

河南第十届省赛-B情报传递

第十二届湖南省省赛总结

2021卓见杯第三届CCPC河南省省赛所有题超详细题解附加榜单真题解析,简单代码+详细注释+思想,要看的,补题的速速点进来 2021 10.30

蓝桥杯——2020第十一届C/C++真题[省赛][B组]