poj 3114 Countries in War】的更多相关文章

POJ 3114 Countries in War 题目链接 题意:给定一个有向图.强连通分支内传送不须要花费,其它有一定花费.每次询问两点的最小花费 思路:强连通缩点后求最短路就可以 代码: #include <cstdio> #include <cstring> #include <vector> #include <queue> #include <stack> #include <algorithm> using namesp…
                                Countries in War Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3672   Accepted: 1057 Description In the year 2050, after different attempts of the UN to maintain peace in the world, the third world war b…
http://poj.org/problem?id=3114 #include <cstdio> #include <cstring> #include <queue> #include <algorithm> #define maxn 300000 using namespace std; <<; int head[maxn],head1[maxn],dfn[maxn],low[maxn],belong[maxn],stack1[maxn],d…
题目链接 题意 : 给你两个城市让你求最短距离,如果两个城市位于同一强连通分量中那距离为0. 思路 :强连通分量缩点之后,求最短路.以前写过,总感觉记忆不深,这次自己敲完再写了一遍. #include <cstdio> #include <cstring> #include <iostream> #include <vector> #include <stack> #include <queue> #include <algor…
Countries in War Time Limit: 1000MS Memory Limit: 65536K Description In the year 2050, after different attempts of the UN to maintain peace in the world, the third world war broke out. The importance of industrial, commercial and military secrets obl…
题目大意: 在一个有向图中,每两点间通信需要一定的时间,但同一个强连通分量里传递信息不用时间,给两点u,v求他们最小的通信时间.   解题过程: 1.首先把强连通分量缩点,然后遍历每一条边来更新两个强联通分量之间的距离.. 2.直接Floyd会超时,应该用dijstra或者spfa做k次最短路.   犯的错误:前向星数组开的太小,一直超时.  …
题目大意: 给定一些城市,然后再给一些寄信的路信,A,B,H代表把信从A城市寄到B城市需要H小时. 如果没有直接可以寄达的,可以先通过另外一个城市到达,比如A,B可以寄信,B,C可以寄信,那么,A,C也可以寄信. 其中两个城市之间如果可以相互寄信的话,那么这两个城市是属于一个国家的,寄信可以通过电子邮件,所以所需的时间为0. 题目中有K个询问,输入A,B询问A到B之间寄信最少需要多少时间 题目分析: 先求出强联通然后构图求最短路. #include <iostream> #include &l…
题目链接:http://poj.org/problem?id=3114 思路:题目要求很简单,就是求两点之间的花费的最短时间,不过有一个要求:如果这两个city属于同一个国家,则花费时间为0.如何判断一个是属于同一个国家呢?就要缩点了,这样属于同一个强连通分量的点就是属于同一个国家了.然后就是SPFA求最短路. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm>…
http://poj.org/problem?id=3114 题意:有n个城市,m条边,由a城市到b城市的通信时间为w,若a城市与b城市连通,b城市与a城市也连通,则a,b城市之间的通信时间为0,求出从s到t的最少通信时间. 思路:先由Tarjan算法求出图中的连通分量,则在同一个连通分量里的城市之间的通信时间w更新为0,然后利用spfa求出s城市与t城市之间的最短路,即为最少通信时间. #include <stdio.h> #include <string.h> #include…
Tug of War Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 8187   Accepted: 2204 Description A tug of war is to be arranged at the local office picnic. For the tug of war, the picnickers must be divided into two teams. Each person must b…