题目描述

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
 /*
问题
输入节点数和边数,起点和终点,以及每一条边,计算从起点到终点再返回起点途中最少要经过几个顶点,重复的点不计。 解题思路
采用Dijkstra算法求一下起点到个点的最短路,然后将走过的点标记一下,再求一下终点到其他点的最短距离,标记过的点
不计算就可以了。
*/
#include<cstdio>
#include<cstring>
int e[][],book[],n,m,ans;
void Dijkstra(int s);
int main()
{
int T,u,v,a,b,i,j;
scanf("%d",&T);
while(T--){
scanf("%d%d%d%d",&n,&m,&a,&b);
for(i=;i<n;i++){
for(j=;j<n;j++){
e[i][j] = i==j?:;
}
}
memset(book,,sizeof(book));
while(m--){
scanf("%d%d",&u,&v);
e[u][v]=;
}
ans=;
Dijkstra(a);
Dijkstra(b);
printf("%d\n",ans);
}
return ;
} void Dijkstra(int s)
{
int dis[],bk[]={},i,j;
for(i=;i<n;i++)
dis[i]=e[s][i]; dis[s]=;
int u=;
bk[s]=;
for(i=;i<n;i++){
int mina=;
for(j=;j<n;j++){
if(bk[j] == && dis[j] < mina){
dis[j]=mina;
u=j;
}
}
bk[u]=;
if(book[u] == )
ans++;
book[u]=;
for(j=;j<n;j++){
if(bk[j] == && dis[j] < e[u][j]){
dis[j]=e[u][j];
}
}
}
}

Checkpoints(第十一届河南省省赛真题)的更多相关文章

  1. 求XF+闭包(第十一届河南省省赛真题)

    题目描述 如何设计一个好的数据库不仅仅是一个理论研究问题,也是一个实际应用问题.在关系数据库中不满足规范化理论的数据库设计会存在冗余.插入异常.删除异常等现象. 设R(U)是一个关系模式,U={ A1 ...

  2. ACM 第十一届 河南省省赛A题 计划日

    一.题目描述如下: 二.思路分析 其实这个如果是一个填空题,可以直接用Excel快速计算出来,反而用代码比较麻烦 说一下我的代码的思路: 1.如果N大于本月剩下的天数,就先从N天里减去本月剩下的天数, ...

  3. 2016 第七届蓝桥杯 c/c++ B组省赛真题及解题报告

    2016 第七届蓝桥杯 c/c++ B组省赛真题及解题报告 勘误1:第6题第4个 if最后一个条件粗心写错了,答案应为1580. 条件应为abs(a[3]-a[7])!=1,宝宝心理苦啊.!感谢zzh ...

  4. 第十届蓝桥杯JavaB组省赛真题

    试题 A: 组队 本题总分:5 分 [问题描述] 作为篮球队教练,你需要从以下名单中选出 1 号位至 5 号位各一名球员, 组成球队的首发阵容. 每位球员担任 1 号位至 5 号位时的评分如下表所示. ...

  5. Python解答蓝桥杯省赛真题之从入门到真题(二刷题目一直更新)

    蓝桥刷题 原文链接: https://github.com/libo-sober/LanQiaoCup Python解答蓝桥杯省赛真题之从入门到真题 不同字串 """ 一 ...

  6. 第九届蓝桥杯JavaC组决(国)赛真题

    1:年龄问题 s夫人一向很神秘.这会儿有人问起她的年龄,她想了想说: "20年前,我丈夫的年龄刚好是我的2倍,而现在他的年龄刚好是我的1.5倍". 你能算出s夫人现在的年龄吗? 这 ...

  7. Java实现第十一届蓝桥杯JavaB组 省赛真题

    试题 A: 指数计算 本题总分:5 分 [问题描述] 7 月 1 日是建党日,从 1921 年到 2020 年, 已经带领中国人民 走过了 99 年. 请计算:7 ^ 2020 mod 1921,其中 ...

  8. 第十届蓝桥杯JavaC组省赛真题

    试题 A: 求和 本题总分:5 分 [问题描述] 小明对数位中含有 2.0.1.9 的数字很感兴趣,在 1 到 40 中这样的数包 括 1.2.9.10 至 32.39 和 40,共 28 个,他们的 ...

  9. 第九届蓝桥杯JavaA组省赛真题

    解题代码部分来自网友,如果有不对的地方,欢迎各位大佬评论 题目1.分数 题目描述 1/1 + 1/2 + 1/4 + 1/8 + 1/16 + - 每项是前一项的一半,如果一共有20项, 求这个和是多 ...

随机推荐

  1. Android Studio-引用jar及so文件

    一.引用jar文件    1.将jar文件复制.粘贴到app的libs目录中:    2.右键点击jar文件,并点击弹出菜单中的“Add As Library”,将jar文件作为类库添加到项目中:  ...

  2. [smarty] smarty 模板文件中进行字符串与变量的拼接

    // smarty 模板引擎 $arr_tribeLabelList["`$tribe_id`_"]

  3. 在 Ubuntu 16.04上安装 vsFTPd

    在 Ubuntu 16.04上安装 vsFTPd Ubuntu vsFTPd 关于 vsFTPd vsFTPd 代表 Very Secure File Transfer Protocol Daemon ...

  4. [机翻] WIRER ON THE WIRE - SIGNALR协议的非正式描述

    原文 原文很简单,以下为机翻 WIRER ON THE WIRE - SIGNALR协议的非正式描述 我已经看到询问有关SignalR协议的描述的问题出现了很多.哎呀,当我开始关注SignalR时,我 ...

  5. UWP Button添加圆角阴影(二)

    原文:UWP Button添加圆角阴影(二) 阴影 对于阴影呢,WindowsCommunityToolkit中已经有封装好的DropShadowPanel啦,只要引用Microsoft.Toolki ...

  6. LVS健康检查脚本

    #!/bin/bash #============================================================================= VIP=10.10 ...

  7. 转---移动端 h5开发相关内容总结——CSS篇

    作者:伯乐在线专栏作者 - zhiqiang21 如有好文章投稿,请点击 → 这里了解详情 如需转载,发送「转载」二字查看说明 1.移动端开发视窗口的添加 h5端开发下面这段话是必须配置的 meta ...

  8. 【Spark基础】:RDD

    我的代码实践:https://github.com/wwcom614/Spark 1.RDD是Spark提供的核心抽象,全称为Resillient Distributed Dataset,即弹性分布式 ...

  9. canvas 实现签名效果

    效果图 概述 在线签名,现在在很多场景下都能看到,而且在移动端见的比较多. 用canvas和svg都可以实现,而且跨平台能力也很好. canvas基于像素,提供 2D 绘制函数,提供的功能更原始,适合 ...

  10. Docker三剑客之Docker Compose

    一.什么是Docker Compose Compose 项目是Docker官方的开源项目,负责实现Docker容器集群的快速编排,开源代码在https://github.com/docker/comp ...