首页 技术 正文
技术 2022年11月7日
0 收藏 461 点赞 1,114 浏览 1824 个字

tarjan扫一遍后直接判断

最关键的地方就是建边(x[i] <= x[j] && y[i] >= x[j] && y[i] <= y[j]) || (x[i] >= x[j] && x[i] <= y[j] && y[i] >= y[j])

建边条件:x[ i ] < = x [ j ] < = y [ i ] < =y [ j ]或者 x [ j ] < = x [ i ] < = y [ j ] < = y [ i ]

这样的话 i 和 j 肯定是相交的,那么连边 ~i ,j 和 i,~j 这样保证了 i 和 j 是不相交的

如果同一个点的拆分在同一个强连通分量里面,那么就无法实现(因为这样i在同一个环中了)

注意 i 和 i + 1是同一个点拆分得到的

#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cassert>
#include<iomanip>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define C 0.5772156649
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#pragma comment(linker, "/STACK:1024000000,1024000000")using namespace std;const double g=10.0,eps=1e-;
const int N=+,maxn=+,inf=0x3f3f3f;stack<int>s;
int dfn[N],low[N];
int inans[N],ins[N];
int num,index;
int n,m;
int x[N],y[N];
vector<int>v[N];
void tarjan(int u)
{
ins[u]=;
dfn[u]=low[u]=++index;
s.push(u);
for(int i=;i<v[u].size();i++)
{
int x=v[u][i];
if(dfn[x]==)
{
tarjan(x);
low[u]=min(low[u],low[x]);
}
else if(ins[x]==)low[u]=min(low[u],dfn[x]);
}
if(dfn[u]==low[u])
{
++num;
while(!s.empty()){
int k=s.top();
s.pop();
ins[k]=;
inans[k]=num;
if(k==u)break;
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie();
memset(inans,,sizeof inans);
memset(ins,,sizeof ins);
memset(dfn,,sizeof dfn);
memset(low,,sizeof low);
for(int i=;i<=*m;i++)v[i].clear();
while(!s.empty())s.pop();
index=num=;
cin>>n>>m;
for(int i=;i<=m;i++)
{
cin>>x[i]>>y[i];
if(x[i]>y[i])swap(x[i],y[i]);
}
for(int i=;i<=m;i++)
for(int j=i+;j<=m;j++)
if((x[i] <= x[j] && y[i] >= x[j] && y[i] <= y[j]) || (x[i] >= x[j] && x[i] <= y[j] && y[i] >= y[j]))
{
v[*i-].push_back(*j);
v[*j].push_back(*i-);
v[*j-].push_back(*i);
v[*i].push_back(*j-);
}
for(int i=;i<=*m;i++)
if(!dfn[i])
tarjan(i);
bool f=;
for(int i=;i<*m;i+=)
if(inans[i]==inans[i+])
{
f=;
break;
}
if(f)cout<<"the evil panda is lying again"<<endl;
else cout<<"panda is telling the truth..."<<endl;
return ;
}
/****************************************/
上一篇: SPOJ - VLATTICE
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,128
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,600
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,443
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,216
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,851
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,939