Brexit Gym - 101490C
题目链接:Brexit
vector的使用(vector存边),巧用queue,相当于Bfs
1 /* */ 2 # include <iostream> 3 # include <cstdio> 4 # include <cstring> 5 # include <string> 6 # include <memory> 7 # include <cstdlib> 8 # include <cmath> 9 # include <climits> 10 # include <cctype> 11 # include <cassert> 12 # include <utility> 13 # include <deque> 14 # include <queue> 15 # include <stack> 16 # include <vector> 17 # include <bitset> 18 # include <set> 19 # include <map> 20 # include <functional> 21 # include <algorithm> 22 using namespace std; 23 24 # define lson l,m,rt<<1 25 # define rson m+1,r,rt<<1|1 26 # define lowbit(x)(x&(-x)) 27 # define lcm(a,b)(a*b/__gcd(a,b)) 28 typedef long long ll; 29 const ll mod=1e9+7; 30 const int maxn=2e5+10; 31 const double eps=1e-18; 32 const double pi=acos(-1.0); 33 int n, m, c, l; 34 int de[maxn]; 35 vector<int>nex[maxn]; 36 queue<int>qu; 37 int flag[maxn]; 38 39 int main() 40 { 41 int t; 42 while( ~ scanf("%d%d%d%d", &n, &m, &c, &l) ) 43 { 44 for(int i=1; i<=n; i++ ) 45 { 46 nex[i].clear(); 47 de[i]=0; 48 flag[i]=0; 49 } 50 51 while( !qu.empty() ) 52 qu.pop(); 53 for(int i=1; i<=m; i++ ) 54 { 55 int u, v; 56 scanf("%d%d", &u, &v); 57 nex[u].push_back(v); 58 nex[v].push_back(u); 59 de[u]++; 60 de[v]++; 61 } 62 63 flag[l]=1; 64 qu.push(l); 65 while( !qu.empty() ) 66 { 67 int cur=qu.front(); 68 qu.pop(); 69 for(int i=0; i<nex[cur].size(); i++ ) 70 { 71 de[nex[cur][i]]--; 72 if( de[nex[cur][i]]<=nex[nex[cur][i]].size()/2 && flag[nex[cur][i]]==0 ) 73 { 74 flag[nex[cur][i]] = 1;//避免重复入栈 75 qu.push(nex[cur][i]); 76 } 77 } 78 } 79 if( flag[c]==1 ) 80 cout<<"leave"<<endl; 81 else 82 cout<<"stay"<<endl; 83 } 84 return 0; 85 }