当前位置:网站首页>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;
}
边栏推荐
- Use non recursive method to realize layer traversal, preorder traversal, middle order traversal and post order traversal in binary tree
- Jar package
- C语言:随机生成数+归并排序
- 屈辱、抗争、逆转,三十年,中国该赢微软一次了
- docker部署mysql 实现远程连接[通俗易懂]
- leetcode-136.只出现一次的数字
- 基于神经网络的帧内预测和变换核选择
- Blue Bridge Training (additional interview questions) day 7
- Countdown 2 days! 2022 China Computing Conference: Mobile cloud invites you to meet with computing network for innovative development
- 不用Swagger,那我用啥?
猜你喜欢

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

不用Swagger,那我用啥?

Rust from introduction to mastery 01 introduction

gicv3 spi register

FFT海浪模拟

Countdown 2 days! 2022 China Computing Conference: Mobile cloud invites you to meet with computing network for innovative development

Customized template in wechat applet

Children's programming electronic society graphical programming level examination scratch Level 2 real problem analysis (judgment question) June 2022

ES6 null merge operator (?)

我秃了!唯一索引、普通索引我该选谁?
随机推荐
拒绝服务 DDoS 攻击
数据库系统原理与应用教程(058)—— MySQL 练习题(二):单选题
今日睡眠质量记录75分
leetcode-136.只出现一次的数字
IP电话系统和VoIP系统使用指南
gicv3 spi register
基于神经网络的帧内预测和变换核选择
Some thoughts on.Net desktop development
C语言学生成绩管理系统详解[通俗易懂]
Debezium系列之:2.0.0.Beta1的重大变化和新特性
Blue Bridge Training (additional interview questions) day 7
Leetcode 笔记 118. 杨辉三角
Use non recursive method to realize layer traversal, preorder traversal, middle order traversal and post order traversal in binary tree
Gamestop bear market entered NFT trading, and established game retailers took advantage of Web3 to make a second spring
性能超群!牛津&上海AI Lab&港大&商汤&清华强强联手,提出用于引用图像分割的语言感知视觉Transformer!代码已开源...
Extended operator
Leetcode notes 566. Reshaping the matrix
JWT 登录认证 + Token 自动续期方案,写得太好了!
Excellent performance! Oxford, Shanghai, AI Lab, Hong Kong University, Shangtang, and Tsinghua have joined forces to propose a language aware visual transformer for reference image segmentation! Open
基于深度学习的超分辨率重建