博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
uva 610 强连通分量 / 桥
阅读量:5295 次
发布时间:2019-06-14

本文共 3028 字,大约阅读时间需要 10 分钟。

  Street Directions 

According to the Automobile Collision Monitor (ACM), most fatal traffic accidents occur on two-way streets. In order to reduce the number of fatalities caused by traffic accidents, the mayor wants to convert as many streets as possible into one-way streets. You have been hired to perform this conversion, so that from each intersection, it is possible for a motorist to drive to all the other intersections following some route.

You will be given a list of streets (all two-way) of the city. Each street connects two intersections, and does not go through an intersection. At most four streets meet at each intersection, and there is at most one street connecting any pair of intersections. It is possible for an intersection to be the end point of only one street. You may assume that it is possible for a motorist to drive from each destination to any other destination when every street is a two-way street.

Input 

The input consists of a number of cases. The first line of each case contains two integers n and m. The number of intersections is n ( $2 \leŸ n \leŸ 1000$), and the number of streets is m. The next m lines contain the intersections incident to each of the m streets. The intersections are numbered from 1 to n, and each street is listed once. If the pair $i\ j$ is present, $j\ i$ will not be present. End of input is indicated by n = m = 0.

Output 

For each case, print the case number (starting from 1) followed by a blank line. Next, print on separate lines each street as the pair $i\ j$ to indicate that the street has been assigned the direction going from intersection i to intersection j. For a street that cannot be converted into a one-way street, print both $i\ j$ and $j\ i$ on two different lines. The list of streets can be printed in any order. Terminate each case with a line containing a single `#' character.

Note: There may be many possible direction assignments satisfying the requirements. Any such assignment is acceptable.

Sample Input 

7 101 21 32 43 44 54 65 76 72 53 67 91 21 31 42 43 44 55 65 77 60 0

Sample Output 

11 22 43 13 64 35 25 46 46 77 5#21 22 43 14 14 34 55 45 66 77 5#


Miguel A. Revilla
1999-03-24
tarjan遍历一遍,标记那些边是回边,需要走的非回边,桥,即可:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;#define LL long long#define UINT unsigned int#define MAX_INT 0x7fffffff#define cint const int#define MAXN 1111#define MAXM 1111111struct edge{ int u, v, nxt;}e[MAXM];int h[MAXN], cc, n, m;void add(int u, int v){ e[cc]=(edge){u, v, h[u]}; h[u]=cc++; e[cc]=(edge){v, u, h[v]}; h[v]=cc++;}int dfn[MAXN], low[MAXN], vis[MAXM];int tsp;void tarjan(int u){ dfn[u] = low[u] = ++tsp; for(int i=h[u]; i!=-1; i=e[i].nxt){ int v = e[i].v; if(vis[i] || u==v){ if(u==v) vis[i]=1, vis[i^1]=-1; continue; } vis[i]=1, vis[i^1]=-1; //走的边,反向边 if(!dfn[v]) tarjan(v); low[u] = min(low[u], low[v]); if(dfn[u]

转载于:https://www.cnblogs.com/ramanujan/p/3379810.html

你可能感兴趣的文章
bash使用规则
查看>>
AVL数
查看>>
第二章练习
查看>>
ajax2.0
查看>>
C#时间截
查看>>
C语言程序设计II—第九周教学
查看>>
全栈12期的崛起之捡点儿有用的说说
查看>>
基础类型
查看>>
属性动画
查看>>
标识符
查看>>
Sqli labs系列-less-4 这关好坑!!!
查看>>
路由跟踪工具0trace
查看>>
给大家分享一张CSS选择器优选级图谱 !
查看>>
Win7中不能调试windows service
查看>>
boost库使用:vs2013下boost::container::vector编译出错解决
查看>>
通过httplib2 探索的学习的最佳方式
查看>>
理解运算符重载 4
查看>>
快来熟练使用 Mac 编程
查看>>
第二周
查看>>
Node.js 入门:Express + Mongoose 基础使用
查看>>