当前位置:网站首页>L3-1 then don't worry (30 points) - pit point, test point analysis
L3-1 then don't worry (30 points) - pit point, test point analysis
2022-04-21 22:18:00 【Echo_ ac】
Ideas
The problem is to follow A A A To B B B The number of paths , And judge from A A A Whether all paths pass through B B B . We use memory search to speed up .
This is mainly to talk about pit points , This may happen to the problem :
from A A A To B B B Fully meet the conditions of the topic , But many friends may not handle it well , Let's test this example .
5 5
1 2
2 3
3 5
4 5
2 4
1 2

AC Code
#include<bits/stdc++.h>
#define rep(i,x,y) for(int i=x; i<=y; ++i)
#define per(i,x,y) for(int i=x; i>=y; --i)
#define pushk push_back
#define popk pop_back
#define mem(a,b) memset(a,b,sizeof a)
#define ll long long
#define lp p<<1
#define rp p<<1|1
#define endl '\n'
#define INF 0x3f3f3f3f
using namespace std;
const int N = 520;
vector<int> g[N];
int A,B;
int cnt1=0,cnt2=0;
ll dp[N];
int f[N][N];
ll dfs(int u) {
if(dp[u]) return dp[u];
if(g[u].size()==0) {
if(u==B) dp[u]=1;
else dp[u]=0;
return dp[u];
}
if(u==B) return dp[u]=1;
ll res=0;
for(auto &it : g[u]) {
res+=dfs(it);
}
return dp[u]=res;
}
ll dfs2(int u) {
if(dp[u]) return dp[u];
if(g[u].size()==0) {
return dp[u]=1;
}
if(u==B) return dp[u]=1;
ll res=0;
for(auto &it : g[u]) {
res+=dfs2(it);
}
return dp[u]=res;
}
int main() {
int n,m;
cin>>n>>m;
rep(i,1,m) {
int u,v;
cin>>u>>v;
g[u].pushk(v);
f[u][v]=1;
}
cin>>A>>B;
ll ans=dfs(A);
rep(i,1,n) dp[i]=0;
ll tmp=dfs2(A);
cout<<ans<<" ";
if(tmp==ans) puts("Yes");
else puts("No");
return 0;
}
版权声明
本文为[Echo_ ac]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204212211585386.html
边栏推荐
- Byte stream write input
- Smart Chemical Park solutions
- [ES6] let and const commands
- ROS robot from starting point to end point (IV) reproduction of blue bridge cloud practice
- Intensive reading of Fanfan's anti attack paper (II) CVPR 2021 yuan learning training simulator for ultra efficient black box attack (Tsinghua)
- Outsourcing student management system architecture design document
- Echart writes a large screen showing a circular edge gradient histogram
- 【ES6】变量的解构赋值
- CC10000.ZABBIX———————————————
- LeetCode146-LRU缓存-模拟-双向链表-哈希表-数据结构-操作系统
猜你喜欢

AUTOCAD——三种箭头的画法

ROS robot from starting point to end point (IV) reproduction of blue bridge cloud practice

CC10000.MySQL———————————————

Smart Chemical Park solutions

INT 102_ TTL 09

L1-058 6翻了 (15 分)

Download and install the vscade plug-in package offline

软件设计师——第六章:系统安全分析与设计

解锁OpenHarmony技术日!年度盛会,即将揭幕!

【VSCode】调试器debugger详细使用手册
随机推荐
L1-058 6翻了 (15 分)
L2-3 完全二叉树的层序遍历 (25 分)——递归还原二叉树
ROS——使用OpenCV实现摄像头的发送和接收
How can "Xiaodeng" enterprises solve the problem of weak password in AD domain?
外包学生管理系统详细架构设计文档
mysql读写分离
算法--合并K个升序链表(Kotlin)
Byte stream write input
Kotlin core programming, Android development, interview answer handler
EventBridge 集成云服务实践
【ES6】字符串的扩展
汇编编写中断
CC10000.MySQL———————————————
[untitled]
外包學生管理系統架構設計文檔
Building local canal middleware for data migration -- Inspiration from cache breakdown
Windowns offline wsl2 installation
【ES6】Promise
软件设计师——第六章:系统安全分析与设计
Number to thousand separator number