题目描述

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. file新建文件及文件夹

    1.获取包名的根目录:mRootPath = getFilesDir().getParent(); // ====mRootPath===/data/data/com.yoyu.file  获取SD卡 ...

  2. vdscode连接git服务器(以码云为例)

    准备工作:先下载并安装git客户端 1.在码云或者github上新建项目,获得新建项目的地址,得到一个类似:https://gitee.com/zhangshitongsky/vueTest.git ...

  3. ue4开发入门教程

    ue4是一套开源跨平台的游戏引擎,游戏画质3A水准,具有强大的材质编辑器,各种插件齐全.想要学习ue4的,可以参考这篇文章作为入门. 学习这篇文章,建议具有一定的C++基础,对游戏有一定了解. 1.首 ...

  4. DEV通过FindFilterText自动检索gridview内容

    private void TreeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { if (names!=nul ...

  5. 背水一战 Windows 10 (61) - 控件(媒体类): InkCanvas 涂鸦编辑

    [源码下载] 背水一战 Windows 10 (61) - 控件(媒体类): InkCanvas 涂鸦编辑 作者:webabcd 介绍背水一战 Windows 10 之 控件(媒体类) InkCanv ...

  6. python--partial偏函数

    new_func = partial(函数名,参数),  生成一个新的函数, 新的函数中参数是partial固定时的参数 例1: from functools import partial def f ...

  7. 201621123018《java程序设计》第13周作业总结

    1. 本周学习总结 2. 为你的系统增加网络功能(购物车.图书馆管理.斗地主等)-分组完成 为了让你的系统可以被多个用户通过网络同时使用,需要为你的系统增加网络功能. 2.1 简述你想为你的系统增加什 ...

  8. Android---------------Handler的学习

    public LocalVPNService() { mHandlerThread = new HandlerThread(TAG); mHandlerThread.start(); mBackgro ...

  9. ssh远程连接不上linux

    远程连接工具是:Xmanager Enterprise 5-->Xshell linux 发行版本是:CentOS-6.3-x86_64 问题:ssh一直都可以远程连接上linux,一段时间后突 ...

  10. java String 内存模型

    关于java的内存模型,参照以下的一篇文章: https://isudox.com/2016/06/22/memory-model-of-string-in-java-language/