首页 技术 正文
技术 2022年11月12日
0 收藏 827 点赞 3,137 浏览 1739 个字

题目链接

BZOJ1997

题解

显然相交的两条边不能同时在圆的一侧,\(2-sat\)判一下就好了

但这样边数是\(O(m^2)\)的,无法通过此题

但是\(n\)很小,平面图 边数上界为\(3n – 6\),所以过大的\(m\)可以判掉

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<map>
#define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt)
#define REP(i,n) for (int i = 1; i <= (n); i++)
#define mp(a,b) make_pair<int,int>(a,b)
#define cls(s) memset(s,0,sizeof(s))
#define cp pair<int,int>
#define LL long long int
using namespace std;
const int maxn = 10005,maxm = 8000005,INF = 1000000000;
inline int read(){
int out = 0,flag = 1; char c = getchar();
while (c < 48 || c > 57){if (c == '-') flag = -1; c = getchar();}
while (c >= 48 && c <= 57){out = (out << 3) + (out << 1) + c - 48; c = getchar();}
return out * flag;
}
int h[maxn],ne;
struct EDGE{int to,nxt;}ed[maxm];
int n,m,N,pos[maxn],a[maxn],b[maxn],vis[maxn];
int dfn[maxn],low[maxn],Scc[maxn],st[maxn],scci,cnt,top;
inline void build(int u,int v){ed[++ne] = (EDGE){v,h[u]}; h[u] = ne;}
void dfs(int u){
dfn[u] = low[u] = ++cnt;
st[++top] = u;
Redge(u){
to = ed[k].to;
if (!dfn[to]){
dfs(to);
low[u] = min(low[u],low[to]);
}
else if (!Scc[to]) low[u] = min(low[u],dfn[to]);
}
if (dfn[u] == low[u]){
scci++;
do {
Scc[st[top]] = scci;
}while (st[top--] != u);
}
}
int main(){
int T = read();
while (T--){
n = read(); m = read();
REP(i,m) a[i] = read(),b[i] = read(),vis[i] = false;
REP(i,n) pos[read()] = i;
if (m > 3 * n - 6) {puts("NO"); continue;}
REP(i,m){
a[i] = pos[a[i]]; b[i] = pos[b[i]];
if (a[i] > b[i]) swap(a[i],b[i]);
if (a[i] + 1 == b[i]) vis[i] = true;
}
int tmp = m; m = 0;
REP(i,tmp) if (!vis[i]){
m++;
a[m] = a[i]; b[m] = b[i];
}
N = (m << 1); REP(i,N) h[i] = 0; ne = 0;
int x,y,xx,yy;
for (int i = 1; i <= m; i++){
x = a[i]; y = b[i];
for (int j = i + 1; j <= m; j++){
xx = a[j]; yy = b[j];
if ((x < xx && xx < y && yy > y) || (x < yy && yy < y && xx < x)){
build(i,j + m); build(j + m,i);
}
}
}
cnt = scci = top = 0;
REP(i,N) dfn[i] = low[i] = Scc[i] = 0;
REP(i,N) if (!dfn[i]) dfs(i);
int flag = true;
REP(i,m) if (Scc[i] == Scc[i + m]){
flag = false; break;
}
puts(flag ? "YES" : "NO");
}
return 0;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,084
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,559
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,408
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,181
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,818
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,901