题目大意: 在一个有向图中,每两点间通信需要一定的时间,但同一个强连通分量里传递信息不用时间,给两点u,v求他们最小的通信时间.   解题过程: 1.首先把强连通分量缩点,然后遍历每一条边来更新两个强联通分量之间的距离.. 2.直接Floyd会超时,应该用dijstra或者spfa做k次最短路.   犯的错误:前向星数组开的太小,一直超时.  …
题意: 间谍在战争期间想要传递一份谍报回国,谍报可以在邮局之间传递,但这种传递是单向的,并且会少耗一些时间.但是如果两个邮局在同一个国家的话,那么谍报在这两个邮局之间传递是不消耗时间的.如果几个邮局发出的谍报可以通过一些路径相互到达,那么这些邮局就属于一个国家.那么问题来了:给出一个起点和终点,问最快什么时候能够将谍报传递到. 思路: 先Tarjan缩点,然后跑Dijkstra(Floyd可能会被卡,但是貌似有个哥们[现在应该叫前辈了]多交了几次,卡1000ms过了)(也可以记忆化搜索,spfa…
题目链接: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…
Going from u to v or from v to u? Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 15494   Accepted: 4100 Description In order to make their sons brave, Jiajia and Wind take them to a big cave. The cave has n rooms, and one-way corridors…
Going from u to v or from v to u? Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17383   Accepted: 4660 Description In order to make their sons brave, Jiajia and Wind take them to a big cave. The cave has n rooms, and one-way corridors…
好久没写过这么长的代码了,题解东哥讲了那么多,并查集优化还是很厉害的,赶快做做前几天碰到的相似的题. #include <iostream> #include <algorithm> #include <cstdio> using namespace std; , M = 2e5 + ; ], Next[M * ]; int dfn[N], low[N], n, m, tot, num; ]; void add(int x, int y) { ver[++tot] =…
Popular Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 37111   Accepted: 15124 Description Every cow's dream is to become the most popular cow in the herd. In a herd of N (1 <= N <= 10,000) cows, you are given up to M (1 <= M &…
Going from u to v or from v to u? Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 19234   Accepted: 5182 Description In order to make their sons brave, Jiajia and Wind take them to a big cave. The cave has n rooms, and one-way corridors…
Popular Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 37083   Accepted: 15104 Description Every cow's dream is to become the most popular cow in the herd. In a herd of N (1 <= N <= 10,000) cows, you are given up to M (1 <= M &…