在这个物欲横流的社会

oj冷漠无情

只有这xx还有些温度

越界就越界吧  wrong 怎么回事。。。。

给出一个图

然后给出q次询问

问是否存在v和w分别到u的路径且边不重复

在边双连通分量中 任意两点 都至少存在两条边不重复的路径

那么若u  v w 在同一连通图中

则存在

若不在

则只有u在 v 和 w 中间时才存在

想一想是不是

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <cctype>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#define rap(i, a, n) for(int i=a; i<=n; i++)
#define rep(i, a, n) for(int i=a; i<n; i++)
#define lap(i, a, n) for(int i=n; i>=a; i--)
#define lep(i, a, n) for(int i=n; i>a; i--)
#define rd(a) scanf("%d", &a)
#define rlld(a) scanf("%lld", &a)
#define rc(a) scanf("%c", &a)
#define rs(a) scanf("%s", a)
#define rb(a) scanf("%lf", &a)
#define rf(a) scanf("%f", &a)
#define pd(a) printf("%d\n", a)
#define plld(a) printf("%lld\n", a)
#define pc(a) printf("%c\n", a)
#define ps(a) printf("%s\n", a)
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _ ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = , INF = 0x7fffffff, maxm = , maxh = ;
int n, m, q;
int head[maxn], nex[maxm], cnt, head2[maxn], cnt2;
int pre[maxn], low[maxn], sccno[maxn], dfs_clock, scc_cnt;
int pa[maxn], anc[maxn][maxh + ], deep[maxn], instack[maxn];
int f[maxn];
stack<int> s; struct node
{
int u, v;
}Node[maxm]; void add_(int u, int v)
{
Node[cnt].u = u;
Node[cnt].v = v;
nex[cnt] = head[u];
head[u] = cnt++;
} void add(int u, int v)
{
add_(u, v);
add_(v, u);
} struct edge{
int u, v, next;
}Edge[maxm]; void add2(int u, int v)
{
Edge[cnt2].u = u;
Edge[cnt2].v = v;
Edge[cnt2].next = head2[u];
head2[u] = cnt2++;
} void tarjan(int u,int fa){
low[u] = pre[u] = ++dfs_clock;
s.push(u);
instack[u] = ;
for(int i = head[u]; i != -; i = nex[i])
{
int v = Node[i].v;
if(i == (fa ^ )) continue;
if(!pre[v])
{
tarjan(v, i);
low[u] = min(low[u], low[v]);
}
else if(instack[v])
low[u] = min(low[u], pre[v]); }
if(pre[u] == low[u])
{
scc_cnt++;
for(;;)
{
int x = s.top(); s.pop();
sccno[x] = scc_cnt;
instack[x] = ;
if(x == u) break;
}
}
} int dfs(int u, int fa)
{
for(int i = ; i < maxh; i++)
anc[u][i] = anc[anc[u][i - ]][i - ];
for(int i = head2[u]; i != -; i = Edge[i].next)
{
int v = Edge[i].v;
if(v == fa || deep[v]) continue;
anc[v][] = u;
deep[v] = deep[u] + ;
dfs(v, u);
}
} int lca(int u, int v)
{
if(deep[u] < deep[v]) swap(u, v);
for(int i = maxh; i >= ; i--)
if(deep[anc[u][i]] >= deep[v])
u = anc[u][i]; for(int i = maxh; i >= ; i--)
{
if(anc[u][i] != anc[v][i])
{
u = anc[u][i];
v = anc[v][i];
}
}
if(u == v) return u;
return anc[u][];
} int find(int x)
{
return f[x] == x ? x : (f[x] = find(f[x]));
} void init()
{
rep(i, , maxn) f[i] = i;
mem(head, -);
mem(head2, -);
mem(deep, );
dfs_clock = scc_cnt = cnt = cnt2 = ;
mem(sccno, ); mem(pre, );
mem(low, );
mem(anc, );
mem(instack, );
} int main()
{
int T;
rd(T);
while(T--)
{
init();
rd(n), rd(m), rd(q);
rap(i, , m)
{
int u, v;
rd(u), rd(v);
if(u == v) continue;
add(u, v);
}
for(int i = ; i <= n; i++) if(!pre[i]) tarjan(i, -);
rap(u, , n)
{
for(int i = head[u]; i != -; i = nex[i])
{
int v = Node[i].v;
if(sccno[u] != sccno[v])
{
add2(sccno[u], sccno[v]);
int l = find(sccno[u]), r = find(sccno[v]);
if(l == r) continue;
f[l] = r;
}
}
}
rap(i, , scc_cnt)
if(!deep[i]) deep[i] = , dfs(i, -);
rap(i, , q)
{
int u, v, w;
rd(u), rd(v), rd(w);
if(find(sccno[u]) != find(sccno[v]) || find(sccno[u]) != find(sccno[w]))
{
puts("No");
continue;
}
if(sccno[v] != sccno[w])
{
int lc = lca(sccno[v], sccno[w]);
int ans1 = lca(sccno[u], sccno[v]);
int ans2 = lca(sccno[u], sccno[w]);
int ans3 =lca(lc, sccno[u]);
if(ans3 == lc && (ans1 == sccno[u] || ans2 == sccno[u]))
{
puts("Yes");
}
else
{
puts("No");
}
}
else
{
if(sccno[u] == sccno[v] )
{
puts("Yes");
continue;
}
else
puts("No");
}
}
} return ;
}

ZOJ 4097 Rescue the Princess的更多相关文章

  1. ZOJ 4097 Rescue the Princess 边双缩点+LCA

    给你一个图和三个点U,V,W  问你是否存在从U到V和从U到W的两条边不相交路径 先边双缩点 再每个连通分量搞LCA 最后LCA判 #include<bits/stdc++.h> usin ...

  2. H - Rescue the Princess ZOJ - 4097 (tarjan缩点+倍增lca)

    题目链接: H - Rescue the Princess  ZOJ - 4097 学习链接: zoj4097 Rescue the Princess无向图缩点有重边+lca - lhc..._博客园 ...

  3. sdut 2603:Rescue The Princess(第四届山东省省赛原题,计算几何,向量旋转 + 向量交点)

    Rescue The Princess Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Several days ago, a b ...

  4. 山东省第四届acm.Rescue The Princess(数学推导)

    Rescue The Princess Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 412  Solved: 168 [Submit][Status ...

  5. 计算几何 2013年山东省赛 A Rescue The Princess

    题目传送门 /* 已知一向量为(x , y) 则将它旋转θ后的坐标为(x*cosθ- y * sinθ , y*cosθ + x * sinθ) 应用到本题,x变为(xb - xa), y变为(yb ...

  6. sdutoj 2603 Rescue The Princess

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2603 Rescue The Princess ...

  7. SDUT 2603:Rescue The Princess

    Rescue The Princess Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Several days ago, a b ...

  8. 2013山东省“浪潮杯”省赛 A.Rescue The Princess

    A.Rescue The PrincessDescription Several days ago, a beast caught a beautiful princess and the princ ...

  9. 山东省赛A题:Rescue The Princess

    http://acm.sdibt.edu.cn/JudgeOnline/problem.php?id=3230 Description Several days ago, a beast caught ...

随机推荐

  1. arcgis api 3.x for js 共享干货系列之二自定义 Navigation 控件样式风格(附源码下载)

    0.内容概览 自定义 Navigation 控件样式风格 源码下载 1.内容讲解 arcgis api 3.x for js 默认的Navigation控件样式风格如下图:这样的风格不能说不好,各有各 ...

  2. 六、Drawable

    Drawable表示的是一种可以在Canvas上进行绘制的抽象的概念. 1.Drawable简介 Drawable是一个抽象类,是所有Drawable对象的基类,每个具体的Drawable都是它的子类 ...

  3. PM真的不是PM

    上周写了一篇<PM意识2.0>,前同事老A留言给我说:“PM已死!”一句话勾起很多回忆啊~当年,我们在一家内资IT公司,我是质量总监,他是研发总监,带四五个PM.老A负责所有项目的计划和监 ...

  4. Ext.grid.panel 改变某一行的字体颜色

    grid.getStore().addListener('load', handleGridLoadEvent); function handleGridLoadEvent(store, record ...

  5. Linux 中磁盘容量配额

    linux的设计之处就是为了多用户同时执行不同的任务,但是硬件资源是有限的,不能让一个用户无限制的上传文件,如果不加以限制,那么磁盘最终将会被充满,对此我们应该使用uquota来加以限制. 1.quo ...

  6. powerdesigner生成mysql带注释的ER图

    1.安装PowerDesigner的 参考 https://blog.csdn.net/sinat_34104446/article/details/79885141 2配置逆向工程 2.1新建模型p ...

  7. Thinkphp volist 多重循环原样输出数组key值的使用总结

    最近因为项目的缘故,要使用到volist.在这个过程中,遇到了一些小问题,主要就是volist在循环输出多重数据的时候,如何输出key.网上查阅了不少资料,很失望的是,大多资料就是粘贴复制Thinkp ...

  8. new 和 newInstance 的区别

    初始化一个类,生成一个实例的时候:newInstance() 和 new 有什么区别? 用newInstance与用new是区别的,区别在于创建对象的方式不一样,前者是使用类加载机制,那么为什么会有两 ...

  9. 我的第一个python web开发框架(28)——定制ORM(四)

    在数据库操作时,新增记录也是必不可少的,接下来我们应用字典的特性来组合sql语句 先上产品新增接口代码 @post('/api/product/') def callback(): "&qu ...

  10. 1.5 下载和安装VMWare

    搭建虚拟环境一般都有两种方法,一种是系统自带的虚拟机,还有一种是下载VMware,Win8和Win10都自带有虚拟机,但是都不是自动开启的,所以我们必须手动开启. 一.Win10开启虚拟机 在命令行输 ...