Call to your teacher
x有y的电话号码,也就是说x可以给y打,y可以给所拥有的号码打,依此类推,最后有没有一个人有n的号码
单向的结构,代码呢?
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <bits/stdc++.h> using namespace std; int fa[60],n,m; int main(){ ios::sync_with_stdio(0); while(cin >> n >> m){ fa[1] = 1; for(int i = 2; i <= n; i++) fa[i] = 0; for(int i = 0; i < m; i++){ int x,y; cin >> x >> y; if(fa[x]) fa[y] = 1; } if(fa[n]) cout << "Yes" << endl; else cout << "No" << endl; } return 0; }