Cat Snuke and a Voyage
https://vjudge.net/contest/272421#problem/C
题意:
给出一个有向图,问1->n能否两步到达。
分析:
用搜索做,搜索不怎么会。。。。
因为是水题,而且只要求恰好两条路是否能到,so。。。。。。
我就是找第一个和最后一个,恰好是只有两条路时才有可能,否则不可能。
代码:
#include<iostream> using namespace std; const int maxn=200010; int a1[maxn],a2[maxn]; int n,m; int main(){ cin>>n>>m; for(int i=0;i<m;i++){ int x,y; cin>>x>>y; if(x==1) a1[y]=1; if(y==n) a2[x]=1; } for(int i=2;i<n;i++){ if(a1[i]&&a2[i]){ cout<<"POSSIBLE"<<endl; return 0; } } cout<<"IMPOSSIBLE"<<endl; return 0; }