边双无法确定

缩完边双就是一棵树

树上差分随意弄一下吧...

#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
namespace remoon {
#define re register
#define de double
#define le long double
#define ri register int
#define ll long long
#define sh short
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define tpr template <typename ra>
#define rep(iu, st, ed) for(ri iu = st; iu <= ed; iu ++)
#define drep(iu, ed, st) for(ri iu = ed; iu >= st; iu --)
extern inline char gc() {
static char RR[], *S = RR + , *T = RR + ;
if(S == T) fread(RR, , , stdin), S = RR;
return *S ++;
}
inline int read() {
int p = , w = ; char c = gc();
while(c > '' || c < '') { if(c == '-') w = -; c = gc(); }
while(c >= '' && c <= '') p = p * + c - '', c = gc();
return p * w;
}
int wr[], rw;
#define pc(iw) putchar(iw)
tpr inline void write(ra o, char c = '\n') {
if(!o) pc('');
if(o < ) o = -o, pc('-');
while(o) wr[++ rw] = o % , o /= ;
while(rw) pc(wr[rw --] + '');
pc(c);
}
tpr inline void cmin(ra &a, ra b) { if(a > b) a = b; }
tpr inline void cmax(ra &a, ra b) { if(a < b) a = b; }
tpr inline bool ckmin(ra &a, ra b) { return (a > b) ? a = b, : ; }
tpr inline bool ckmax(ra &a, ra b) { return (a < b) ? a = b, : ; }
}
using namespace std;
using namespace remoon; #define sid 500050
int n, m, cnp = , tim, top, bcc;
int id[sid], jg[sid], U[sid], V[sid], dfn[sid], low[sid], st[sid];
int nxt[sid], node[sid], cap[sid], bel[sid]; inline void addedge(int u, int v, int w = ) {
id[cnp + ] = id[cnp + ] = w;
nxt[++ cnp] = cap[u]; cap[u] = cnp; node[cnp] = v;
nxt[++ cnp] = cap[v]; cap[v] = cnp; node[cnp] = u;
} #define cur node[i]
inline void tarjan(int o, int fa) {
st[++ top] = o;
dfn[o] = low[o] = ++ tim;
for(int i = cap[o]; i; i = nxt[i])
if(!dfn[cur]) {
tarjan(cur, i), cmin(low[o], low[cur]);
if(low[cur] <= dfn[o]) continue;
int p; ++ bcc;
while(p != cur) bel[p = st[top --]] = bcc;
}
else if((i ^ ) != fa) cmin(low[o], dfn[cur]);
} int eg[sid], vis[sid], up[sid], down[sid];
int son[sid], sz[sid], dep[sid], anc[sid], fa[sid]; inline void dfs(int o) {
sz[o] = ;
for(int i = cap[o]; i; i = nxt[i])
if(cur != fa[o]) {
eg[id[i]] = cur;
fa[cur] = o; dep[cur] = dep[o] + ;
dfs(cur); sz[o] += sz[cur];
if(sz[son[o]] < sz[cur]) son[o] = cur;
}
} inline void dfs(int o, int ac) {
anc[o] = ac;
if(!son[o]) return;
dfs(son[o], ac);
for(int i = cap[o]; i; i = nxt[i])
if(cur != fa[o] && cur != son[o]) dfs(cur, cur);
} inline int lca(int u, int v) {
int pu = anc[u], pv = anc[v];
while(pu != pv) {
if(dep[pu] < dep[pv]) swap(pu, pv), swap(u, v);
u = fa[pu]; pu = anc[u];
}
return (dep[u] < dep[v]) ? u : v;
} inline void cot(int o) {
vis[o] = ;
for(int i = cap[o]; i; i = nxt[i])
if(cur != fa[o])
cot(cur), up[o] += up[cur], down[o] += down[cur];
} int main() { n = read(); m = read();
rep(i, , m) {
U[i] = read(); V[i] = read();
addedge(U[i], V[i]);
}
rep(i, , n) if(!dfn[i]) {
tarjan(i, ); ++ bcc;
while(top) bel[st[top --]] = bcc;
} cnp = ;
memset(cap, , sizeof(cap));
rep(i, , m) {
int u = U[i], v = V[i];
if(bel[u] == bel[v]) jg[i] = ;
else addedge(bel[u], bel[v], i);
} rep(i, , bcc)
if(!dep[i]) dfs(i), dfs(i, i); int q = read();
rep(i, , q) {
int x = read(), y = read();
if(bel[x] == bel[y]) continue;
else {
int lc = lca(bel[x], bel[y]);
up[bel[x]] ++; up[lc] --;
down[bel[y]] ++; down[lc] --;
}
} rep(i, , bcc) if(!vis[i]) cot(i);
rep(i, , m) {
int u = bel[U[i]], v = bel[V[i]];
if(jg[i] == ) printf("%c", 'B');
else {
if(dep[u] < dep[v]) {
if(up[eg[i]]) printf("%c", 'L');
else if(down[eg[i]]) printf("%c", 'R');
else printf("%c", 'B');
}
else {
if(up[eg[i]]) printf("%c", 'R');
else if(down[eg[i]]) printf("%c", 'L');
else printf("%c", 'B');
}
}
}
return ;
}

loj2480 [CEOI2017]One-Way Streets 边双+树上差分的更多相关文章

  1. [Codeforces 555E]Case of Computer Network(Tarjan求边-双连通分量+树上差分)

    [Codeforces 555E]Case of Computer Network(Tarjan求边-双连通分量+树上差分) 题面 给出一个无向图,以及q条有向路径.问是否存在一种给边定向的方案,使得 ...

  2. @loj - 2480@ 「CEOI2017」One-Way Streets

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定一张 n 个点 m 条边的无向图,现在想要把这张图定向. 有 ...

  3. BZOJ 压力 tarjan 点双联通分量+树上差分+圆方树

    题意 如今,路由器和交换机构建起了互联网的骨架.处在互联网的骨干位置的核心路由器典型的要处理100Gbit/s的网络流量. 他们每天都生活在巨大的压力之下.小强建立了一个模型.这世界上有N个网络设备, ...

  4. 有趣的线段树模板合集(线段树,最短/长路,单调栈,线段树合并,线段树分裂,树上差分,Tarjan-LCA,势能线段树,李超线段树)

    线段树分裂 以某个键值为中点将线段树分裂成左右两部分,应该类似Treap的分裂吧(我菜不会Treap).一般应用于区间排序. 方法很简单,就是把分裂之后的两棵树的重复的\(\log\)个节点新建出来, ...

  5. BZOJ 3331 [BeiJing2013]压力-Tarjan + 树上差分

    Solution Tarjan 点双缩点, 加上树上差分计算. 注意特判... 我特判挂了好久呜呜呜 Code #include<cstdio> #include<cstring&g ...

  6. Codechef Sad Pairs——圆方树+虚树+树上差分

    SADPAIRS 删点不连通,点双,圆方树 非割点:没有影响 割点:子树DP一下 有不同颜色,所以建立虚树 在圆方树上dfs时候 如果当前点是割点 1.统计当前颜色虚树上的不连通点对,树形DP即可 2 ...

  7. 【思维题 集合hash 树上差分】11.5撸树

    要注重问题的转化和一些结论的推断 题目描述 要致富,先撸树. 一棵树的形状可以简化为一张 $N$ 个点 $M$ 条边的图,由于装备条件限制,你只有撸两次,也就是删去两条边,当这张图不联通时,就意味着树 ...

  8. BZOJ3331 [BeiJing2013]压力[圆方树+树上差分]

    圆方树新技能get.具体笔记见图连通性问题学习笔记. 这题求无向图的必经点,这个是一个固定套路:首先,一张连通的无向图中,每对点双和点双之间是以一个且仅一个割点连接起来的(如果超过一个就不能是割点了) ...

  9. BZOJ 3331 (Tarjan缩点+树上差分)

    题面 传送门 分析 用Tarjan求出割点,对点-双连通分量(v-DCC)进行缩点,图会变成一棵树 注意v-DCC的缩点和e-DCC不同,因为一个割点可能属于多个v-DCC 设图中共有p个割点和t个v ...

随机推荐

  1. Eng1—English daily notes

    English daily notes 2015年 4月 Phrases 1. As a side note #作为附注,顺便说句题外话,和by the way意思相近,例句: @1:As a sid ...

  2. 2017ACM暑期多校联合训练 - Team 4 1003 HDU 6069 Counting Divisors (区间素数筛选+因子数)

    题目链接 Problem Description In mathematics, the function d(n) denotes the number of divisors of positiv ...

  3. password passphrase passcode 的区别

    In general, passphrases are long passwords and passcodes are numeric-only passwords.

  4. rebbitmq之python_pika监控远程连接及自动恢复(七)

    前言 客户端连接rabbitmq后,如果长时间没有数据的传输,rabbitmq会申请关闭TCP连接,造成该TCP连接下的所有的信道都不可用,很多时候为了传输数据的高效率,我们会先创建一个信道池,这样省 ...

  5. 修改weblogic访问路径应用名称

    第一种:在应用WEB-INF文件夹下创建weblogic.xml文件,内容如下,其中<context-root>/abc</context-root>为路径上的应用名 < ...

  6. 用C++写程序的一些感悟

    前言 近期使用C++有了一些心得很感悟,这里整理一下. 心得1 如果只会使用LabVIEW写程序,还想要进一步深入程序设计,一定要学习一门文本语言. 什么是会用LabVIEW 会用是个比较笼统的概念. ...

  7. shell脚本执行方式

    # BY THE WAY, 其实这块内容算是比较简单的,但是都比较常记得它最基本的两种方式,另外两种却忘记了 1. 利用sh或bash命令执行 sh test.sh bash test.sh 2. 在 ...

  8. H5移动端视频问题(苹果全屏播放问题等)

    iphone上,手动.自动.窗口化等问题 iphone窗口化 解决方案: 通过canvas + video标签结合处理 原理: 获取video的原图帧,通过canavs绘制到页面. 我们一般在苹果上在 ...

  9. hdu 1846(巴什博弈)

    Brave Game Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  10. NIO-3网络通信(非阻塞)

    import java.io.IOException; import java.net.InetSocketAddress; import java.nio.ByteBuffer; import ja ...