P4575 [CQOI2013]图的逆变换
如果新的图里存在边\((u,v)\),那么说明原图中\(u\)的终点和\(v\)的起点是同一个点
于是可以对新图中的每个点维护它的起点和终点,如果有一条边就把对应两个应该相等的点用并查集连起来
最后扫一遍,如果两个点没有边但他们的起点和终点在同一个集合那么说明gg了,否则就是可行的
//minamoto
#include<bits/stdc++.h>
#define R register
#define GG return (void)(puts("No"))
#define fp(i,a,b) for(R int i=a,I=b+1;i<I;++i)
#define fd(i,a,b) for(R int i=a,I=b-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
int read(){
R int res,f=1;R char ch;
while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
return res*f;
}
const int N=1005;
int fa[N],mp[305][305],n,m,u,v;
int find(R int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
void solve(){
memset(mp,0,sizeof(mp)),n=read(),m=read();
fp(i,1,n<<1)fa[i]=i;fp(i,1,m)u=read()+1,v=read()+1,mp[u][v]=1,fa[find(u+n)]=find(v);
fp(i,1,n)fp(j,1,n)if(!mp[i][j]&&find(i+n)==find(j))GG;
puts("Yes");
}
int main(){
// freopen("testdata.in","r",stdin);
int T=read();
while(T--)solve();
return 0;
}
P4575 [CQOI2013]图的逆变换的更多相关文章
- BZOJ 3108: [cqoi2013]图的逆变换
3108: [cqoi2013]图的逆变换 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 627 Solved: 415[Submit][Statu ...
- BZOJ3108 [cqoi2013]图的逆变换
Description 定义一个图的变换:对于一个有向图\(G=(V, E)\),建立一个新的有向图: \(V'=\{v_e|e \in E\}\),\(E'=\{(v_b, v_e)|b=(u,v) ...
- [BZOJ 3108] 图的逆变换
Link: BZOJ 3108 传送门 Solution: 样例教你做题系列 观察第三个输出为No的样例,发现只要存在$edge(i,k),edge(j,k)$,那么$i,j$的出边一定要全部相同 于 ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- 论文解读GCN 1st《 Deep Embedding for CUnsupervisedlustering Analysis》
论文信息 Tittle:<Spectral Networks and Locally Connected Networks on Graphs> Authors:Joan Bruna.Wo ...
- shader复杂与深入:Normal Map(法线贴图)1
转自:http://www.zwqxin.com/archives/shaderglsl/review-normal-map-bump-map.htmlNormal Map法线贴图,想必每个学习计算机 ...
- [离散时间信号处理学习笔记] 8. z逆变换
z逆变换的计算为下面的复数闭合曲线积分: $x[n] = \displaystyle{\frac{1}{2\pi j}}\oint_{C}X(z)z^{n-1}dz$ 式中$C$表示的是收敛域内的一条 ...
- NormalMap 贴图 【转】
转载: http://www.zwqxin.com/archives/shaderglsl/review-normal-map-bump-map.html 说起Normal Map(法线贴图),就 ...
- 译:Local Spectral Graph Convolution for Point Set Feature Learning-用于点集特征学习的局部谱图卷积
标题:Local Spectral Graph Convolution for Point Set Feature Learning 作者:Chu Wang, Babak Samari, Kaleem ...
随机推荐
- HDU 5573 Binary Tree【构造】
几天前模拟区域赛的一道题,今天发现在草稿箱里直接补个博客. 感觉这还是一道很有意思的构造题. 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5573 ...
- Baby Step Giant Step model
******************************************** */ #include <stdio.h> #include <string.h> # ...
- POJ 2240 【这题貌似可以直接FLOYD 屌丝用SPFA通过枚举找正权值环 顺便学了下map】
题意: 给了n种硬币的名称,给了m种硬币间的转换关系. 从任意兑换地点开始兑换,看是否能够通过兑换的方式增加金钱. 思路: 用SPFA不断对各个点进行松弛操作,寻找正权值的环.如果找到则输出Yes. ...
- com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown error 1054
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown error 1054 这个错误困扰了我一个下午 插入数据总是错误 ...
- vue-alioss-组件封装
<template> <div class="vui_alioss_upload"> <div @click="uloadImg()&quo ...
- java 返回json数据
Student st1 = new Student(1, "dg", 18, new Date()); Student st2 = new Student(2 ...
- [Rust] Setup Rust for WebAssembly
In order to setup a project we need to install the nightly build of Rust and add the WebAssembly tar ...
- poj 1258 Agri-Net(Prim)(基础)
Agri-Net Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 44487 Accepted: 18173 Descri ...
- 杭电1232畅通project
畅通project Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- python手记(53)
import sys import pygame from pygame.locals import * import time import math pygame.init() screen=py ...