ceoi 2017 One-Way Streets

题目描述
Once upon a time there was a country with n cities and m bidirectional roads connecting them. Technical development led to faster and larger road vehicles which presented a problem—the roads were becoming too narrow for two vehicles travelling in opposite direction. A decision to solve this problem involved turning all the roads into single-lane, one-way (unidirectional) roads.

Making the roads one-way comes at a cost because some of those pairs of cities that were previously connected might no longer be reachable after the change. The government compiled a list of important pairs of cities for which it has to be possible to start in the first city and reach the second one. Your task is to determine in which direction to direct the traffic on every road. It is guaranteed that a solution exists.

For some roads there is no choice about the direction of traffic if you want to obtain a solution. The traffic will flow from the first to the second city (right direction, indicated by letter R) or from the second city towards the first (left direction, indicated by letter L).

However, for some roads there exists a solution with this road directed left, and another (possibly different) solution with the road directed right. You should indicate such roads with a letter B for both directions.

Output a string of length j. Its i−th character should be
R if all solutions require the i−th road to be directed right
L if all solutions require the i−th road to be directed left
B if a solution exists where the i−th road is directed left, and a solution also exists where the i−th road is directed right
给定一张n 个点m条边的无向图,现在想要把这张图定向。
有p 个限制条件,每个条件形如(xi,yi),表示在新的有向图当中, xi要能够沿着一些边走到yi。现在请你求出,每条边的方向是否能够唯一确定。同时请给出这些能够唯一确定的边的方向。

输入
The first line contains the number of cities n and the number of roads m
The following m lines describe the roads with pairs of numbers ai and bi, which indicate that there is a road between cities ai and bi.
There can be more than one road between the same pair of cities and a road can even connect the city with itself.
The next line contains the number of pairs of cities p that have to be reachable.
The next p lines contain pairs of cities xi and yi, meaning that there has to be a way to start in city xi and reach yi.
第一行两个空格隔开的正整数n,m
接下来m行,每行两个空格隔开的正整数ai,bi,表示ai,bi 之间有一条边。
接下来一行一个整数p表示限制条件的个数。
接下来p行,每行两个空格隔开的正整数xi,yi,描述一个(xi,yi 的限制条件。
输出
Output a string of length m as described in the description of the task.
输出一行一个长度为m 的字符串,表示每条边的答案:

若第i 条边必须得要是ai指向bi 的,那么这个字符串的第i个字符应当为 R;
若第i条边必须得要是bi 指向ai的,那么这个字符串的第i个字符应当为 L;·
否则,若第i条边的方向无法唯一确定,那么这个字符串的第i个字符应当为 B。

题解

这道题是5月份的时候ly神犇就出出来的题,然鹅我太菜了不会写,现在再来想突然就懂了233333
sgx神犇说他会写是树的,然鹅不会写是图的,真的是太强辣!!!orzorzorz%%%%
树的话就暴力lca完事
事实上,这题就是树啊……
先分类讨论一波
假如 n>m 那么就是森林辣,每颗树分别处理就好辣
关键是 n<=m 就比较难搞
但是这种题也不是没有做过((((
很显然是缩点啊
我们把边双压在一起,整张图就变成了一颗树
然后每次暴力lca就完事了
我真的太弱辣
TIPS 由于建的是双向边方便操作链表的cnt 初值最好赋成1,也就是和网络流差不多的操作233
代码就不上了(懒

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值