计蒜客ACM ICPC 2017 Warmup Contest 9--C题
来源:互联网 发布:phpcms和帝国cms 编辑:程序博客网 时间:2024/06/07 10:59
- 时间: 2000ms
- 内存:65536K
A long time ago in a galaxy far, far away, there was a large interstellar trading union, consisting of many countries from all across the galaxy. Recently, one of the countries decided to leave the union. As a result, other countries are thinking about leaving too, as their participation in the union is no longer beneficial when their main trading partners are gone.
You are a concerned citizen of country X, and you want to find out whether your country will remain in the union or not. You have crafted a list of all pairs of countries that are trading partners of one another. If at least half of the trading partners of any given country Y leave the union, country Y will soon follow. Given this information, you now intend to determine whether your home country will leave the union.
Input
The input starts with one line containing four space separated integers C, P, X, and L. These denote the total number of countries (2 ≤ C ≤ 200 000), the number of trading partnerships(1 ≤ P ≤ 300000), the number of your home country (1 ≤ X ≤C) and finally the number of the first country to leave, setting in motion a chain reaction with potentially disastrous consequences (1 ≤ L ≤ C).
This is followed by P lines, each containing two space separated integers Ai and Bi satisfying1 ≤ Ai < Bi ≤ C. Such a line denotes a trade partnership between countries Ai and Bi. No pair of countries is listed more than once.
Initially, every country has at least one trading partner in the union.
Output
For each test case, output one line containing either “leave” or “stay”, denoting whether you home country leaves or stays in the union.
样例输入1
4 3 4 12 32 41 2
样例输出1
stay
样例输入2
5 5 1 13 41 22 31 32 5
样例输出2
leave
#include<iostream>#include<cstring>#include<cstdio>#include<vector>using namespace std;int C,P,X,L;int visited[200001];vector<int>G[200001];void f(int s){for(int i=0;i<G[s].size();i++){int k=G[s][i];visited[k]--;if(visited[k]<=0) continue;if(visited[k]>G[k].size()/2) continue;if(visited[k]<=G[k].size()/2){visited[k]=0;f(k);}}}int main(){int m,n;while(scanf("%d%d%d%d",&C,&P,&X,&L)!=EOF){memset(visited,0,sizeof(visited));for(int i=0;i<P;i++){scanf("%d%d",&m,&n);G[m].push_back(n);G[n].push_back(m);visited[m]++;visited[n]++;}if(X==L){printf("leave\n");continue;}visited[L]=0;f(L);if(visited[X]>0) printf("stay\n");else printf("leave\n");}return 0;}
- 计蒜客ACM ICPC 2017 Warmup Contest 9--C题
- 计蒜客 ACM-ICPC 2017 Warmup Contest 12
- 计蒜客 Bridge Automation(ACM ICPC 2017 Warmup Contest 9)
- 计蒜客 Charles in Charge(ACM ICPC 2017 Warmup Contest 9)
- 计蒜客ACM ICPC 2017 Warmup Contest 9--B题-Battle Simulation
- 计蒜客ACM ICPC 2017 Warmup Contest 9--I题-Older Brother
- 计蒜客ACM ICPC 2017 Warmup Contest 9--I题-Sticky Situation
- 计蒜客 ACM ICPC 2017 Warmup Contest 1 G Game Rank
- ACM ICPC 2017 Warmup Contest 1
- ACM ICPC 2017 Warmup Contest 5
- ACM ICPC 2017 Warmup Contest 6 G
- ACM ICPC 2017 Warmup Contest 1 F. Fleecing the Raffle
- ACM ICPC 2017 Warmup Contest 1 (NCPC 2016)
- ACM ICPC 2017 Warmup Contest 4(ACM Northeastern European Regional Contest,Northern Subregion 2015)
- ACM ICPC 2017 Warmup Contest 6(ACM Google Cup 2011 Invitational Programming Contest)
- ACM ICPC 2017 Warmup Contest 2(ACM Northeastern European Regional Contest,Northern Subregion 2016)
- ACM ICPC 2017 Warmup Contest 8(ACM PolyU International Invitation Contest)
- ACM ICPC 2017 Warmup Contest 1(Nordic Collegiate Programming Contest 2016)
- JAVA小程序--裁判评分系统
- HTML5+JavaScript+CSS实现音乐播放器——难点一:动态生成播放列表
- matlab的gscale函数
- webdriver 等待方法
- 优秀博客地址
- 计蒜客ACM ICPC 2017 Warmup Contest 9--C题
- ggplot2柱形图Y轴坐标扩展的简单方法
- 《多核程序设计》学习笔记:矩阵乘法并行化
- Java线程的同步与死锁
- 【JavaDemo】使用Entry遍历含自定义类的Map集合
- Lavaral5.5 路由, 控制器 向view模板传值的几种方法总结,
- 欢迎关注我的微信公众号:C语言编程技术分享
- Java基础类库之StringBuffer类
- Java基础类库之Runtime类和System类