Cat Snuke and a Voyage --AtCoder
题目描述
There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island ai and Island bi.
Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services.
Help him.
Constraints
3≤N≤200 000
1≤M≤200 000
1≤ai<bi≤N
(ai,bi)≠(1,N)
If i≠j, (ai,bi)≠(aj,bj).
输入
N M
a1 b1
a2 b2
:
aM bM
输出
样例输入
3 2
1 2
2 3
样例输出
POSSIBLE
分析:反正只需要两次即可,直接判断第一个节点后和第n个节点前有没有通。
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#define range(i,a,b) for(int i=a;i<=b;++i)
#define LL long long
#define rerange(i,a,b) for(int i=a;i>=b;--i)
#define fill(arr,tmp) memset(arr,tmp,sizeof(arr))
using namespace std;
int n,m,a,b;
bool vis[],flag;
void init(){
cin>>n>>m;
fill(vis,);
range(i,,m){
cin>>a>>b;
if(flag)continue;
if(a==){
flag=vis[b];
vis[b]=true;
}
else if(b==n){
flag=vis[a];
vis[a]=true;
}
}
}
void solve(){
cout<<(flag?"POSSIBLE":"IMPOSSIBLE")<<endl;
}
int main() {
init();
solve();
return ;
}
Cat Snuke and a Voyage --AtCoder的更多相关文章
- Atcoder At Beginner Contest 068 C - Cat Snuke and a Voyage
C - Cat Snuke and a Voyage Time limit : 2sec / Memory limit : 256MB Score : 300 points Problem State ...
- AtCoder Beginner Contest 068 ABCD题
A - ABCxxx Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement This contes ...
- AtCoder Beginner Contest 068
A - ABCxxx 题意: 给出n,输出“ABCn”就可以了,纯水题. B - Break Number 题意: 给出n,找出从1到n的闭区间内能够被2整除最多次的数. 思路: 直接模拟. 代码: ...
- 【AtCoder】ARC079
ARC079题解 C - Cat Snuke and a Voyage #include <bits/stdc++.h> #define fi first #define se secon ...
- 数学 SRM 690 Div1 WolfCardGame 300
Problem Statement Wolf Sothe and Cat Snuke are playing a card game. The game is played with exa ...
- すぬけ君の塗り絵 / Snuke's Coloring AtCoder - 2068 (思维,排序,贡献)
Problem Statement We have a grid with H rows and W columns. At first, all cells were painted white. ...
- Fennec VS. Snuke --AtCoder
题目描述 Fennec and Snuke are playing a board game.On the board, there are N cells numbered 1 through N, ...
- AtCoder Regular Contest 068E:Snuke Line
题目传送门:https://arc068.contest.atcoder.jp/tasks/arc068_c 题目翻译 直线上有\(0-m\)这\(m+1\)个点,一共有\(m\)辆火车.第\(i\) ...
- AtCoder Beginner Contest 067 D - Fennec VS. Snuke
D - Fennec VS. Snuke Time limit : 2sec / Memory limit : 256MB Score : 400 points Problem Statement F ...
随机推荐
- 笔记-python-standard library-12.1 pickle
笔记-python-standard library-12.1 pickle 1. pickle简介 source code: Lib/pickle.py pickle模块实质上是一个实现p ...
- 配置Spring.NET
先引入关键的程序集 Common.Logging.dll Spring.Core.dll 在配置文件配置中: <configSections> ...... <sectionGrou ...
- Nodejs-文件流
1.什么是流? 流是程序输入输出的一个连续的字节序列. 有文件流,网络流,设备(例如鼠标,键盘,磁盘,调制解调器和打印机)的输入输出都是用流来处理的. 任何数据的最根本表现形式都是二进制. 读取文件 ...
- VMware workstation 9.0中安装Windows server 2012 和 Hyper-v
一.准备工作 首先下载和安装和安装VMware workstation 9.0 下载Windows server 2012 iso镜像文件 二.安装Windows server 2012虚拟机 1.新 ...
- leetcode 【 Sort List 】 python 实现
题目: Sort a linked list in O(n log n) time using constant space complexity. 代码:oj 测试通过 Runtime: 372 m ...
- Backpropagation Through Time (BPTT) 梯度消失与梯度爆炸
Backpropagation Through Time (BPTT) 梯度消失与梯度爆炸 下面的图显示的是RNN的结果以及数据前向流动方向 假设有 \[ \begin{split} h_t & ...
- web 大规模并发访问的解决方案
电商的秒杀和抢购,对我们来说,都不是一个陌生的东西.然而,从技术的角度来说,这对于Web系统是一个巨大的考验.当一个Web系统,在一秒钟内收到数以万计甚至更多请求时,系统的优化和稳定至关重要.这次我们 ...
- eclipse中xml文件报错异常处理
最近一个Javaweb工程中常出现xml文件的xsd验证失败信息,异常如下: <?xml version="1.0" encoding="UTF-8"?& ...
- no for & 100 Array & Uint8Array & Typed Arrays
no for & 100 Array http://hiluluke.cn/ bad function generate100Array() { var arr = new Array(100 ...
- 【BZOJ 5047 空间传送装置】
Time Limit: 20 Sec Memory Limit: 256 MBSubmit: 282 Solved: 121[Submit][Status][Discuss] Descriptio ...