当前位置:网站首页>UVA11175有向图D和E From D to E and Back题解
UVA11175有向图D和E From D to E and Back题解
2022-07-28 12:37:00 【bj_hacker】
题目
链接
https://www.luogu.com.cn/problem/UVA11175
字面描述
D 为有向图, D 的每条边对应 E 的一个结点,若 D有边 uv,则 E 有结点 uv,对于 D 的两条边 uv 和 vw, E 中的两个结点 uv 与 vw 连边。给出 E,判断是否有对应的 D。
思路
本人一开始读了很久题都没读懂,参考了一下题解,简单讲讲思路
- 枚举3个点
- 如果前两个点都有到第三个点的边,记录1
- 如果只有一个有,记录2
- 在第三层循环结束判断记录1和记录2是否同时存在
同时存在,错误
否则,继续
这是因为,两个点可以同时到多个点,但突然出现一个只有一个点能到达的点,这是图就还原不回去了,所以要判断。 - 最后没出现错误,正确
代码实现
#include<bits/stdc++.h>
using namespace std;
const int maxn=300+10;
int n,m,k;
bool vis[maxn][maxn];
inline bool solve(){
for(int i=0;i<m;i++){
for(int j=0;j<m;j++){
bool flag1=false,flag2=false;
for(int k=0;k<m;k++){
if(vis[i][k]&&vis[j][k])flag1=true;
if(vis[i][k]^vis[j][k])flag2=true;
}
if(flag1&&flag2)return false;
}
}
return true;
}
int main(){
scanf("%d",&n);
int N=n;
while(n--){
printf("Case #%d: ",N-n);
memset(vis,false,sizeof(vis));
scanf("%d%d",&m,&k);
for(int i=1;i<=k;i++){
int x,y;
scanf("%d%d",&x,&y);
vis[x][y]=true;
}
if(solve())printf("Yes\n");
else printf("No\n");
}
return 0;
}
边栏推荐
- C language: quick sorting of sequential storage structure
- 力扣 2354. 优质数对的数目
- [ecmascript6] symbol and its related use
- Countdown 2 days! 2022 China Computing Conference: Mobile cloud invites you to meet with computing network for innovative development
- 什么叫杂谈(e网杂谈)
- Blue Bridge Training (additional interview questions) day 7
- Continuous (integration -- & gt; delivery -- & gt; deployment)
- Leetcdoe-342. Power of 4
- You have to apologize if you get involved in the funny shop?
- What is the optimization method of transaction and database
猜你喜欢

GO语言-栈的应用-表达式求值

MySQL practice -- master-slave replication

Shell基础概念和变量

Half wave rectification light LED

SAP UI5 FileUploader 控件实现本地文件上传,接收服务器端的响应时遇到跨域访问错误的试读版

性能超群!牛津&上海AI Lab&港大&商汤&清华强强联手,提出用于引用图像分割的语言感知视觉Transformer!代码已开源...

微信小程序中自定义模板

Leetcode · daily question · 1331. array sequence number conversion · discretization

leetcode-136.只出现一次的数字

火山石投资章苏阳:硬科技,下一个10年相对确定的答案
随机推荐
严格模式——let和const——箭头函数——解构赋值——字符串模板symbol——Set和Map——生成器函数
FFT wave simulation
基于神经网络的帧内预测和变换核选择
Children's programming electronic society graphical programming level examination scratch Level 2 real problem analysis (judgment question) June 2022
数据库系统原理与应用教程(059)—— MySQL 练习题:操作题 1-10(三)
Night God simulator packet capturing wechat applet
使用 Fail2ban 保护 Web 服务器免受 DDoS 攻击
Go language - Application of stack - expression evaluation
无法连接服务器怎么办(原始服务器找不到目标资源)
SQL每日一练(牛客新题库)——第4天:高级操作符
C language: quick sorting of sequential storage structure
火山石投资章苏阳:硬科技,下一个10年相对确定的答案
I copied the bottom of the liquidated NFT, but was locked by opensea
jar包
C语言:归并排序
Beyond istio OSS -- current situation and future of istio Service Grid
Countdown 2 days! 2022 China Computing Conference: Mobile cloud invites you to meet with computing network for innovative development
【安全】 阅读 RFC6749 及理解 Oauth2.0 下的授权码模式
One track education, PHP training, unity of knowledge and practice, popular
酷炫操作预热!代码实现小星球特效