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 ...
随机推荐
- IQueryable与IEnumerable区别
前者可以延迟加载,即执行完后不马上执行数据库语句,用到再加载.
- Diycode开源项目 Glide图片加载分析
1.使用Glide前的准备 1.1.首先要build.gradle中添加 github原地址点击我. 参考博客:Glide-开始! 参考博客:android图片加载库Glide的使用介绍. 参考博 ...
- 读书笔记jvm探秘之一:内存概况
jvm内存大致可以分为六大块: 堆,虚拟机主要内存,可以形象的说,堆是对象的存储库,几乎所有的对象实例和数组都在此分配内存,当然也死于此,jvm垃圾回收机制(简称GC)主要处理的就是这个地方.它被所有 ...
- Java语言基础---逻辑运算(长路短路运算)
长路短路运算的区别 长路与运算&:是指在两边都是整数时,是逐位与运算,在两边是关系运算时,是逻辑运算. 短路与运算&&:是指从左至右,遇到false,则停止后面的运算. 长路或 ...
- day40--mysql step4 SQLAlchemy
1.unique = True 表示启动唯一索 2.有add 必须有commit这样数据才会提交 3.ORM功能 #!/usr/bin/env python # -*- coding:utf-8 -* ...
- Python框架之Django学习笔记(四)
第一个基于Django的页面:Hello World 正如我们的第一个目标,创建一个网页,用来输出这个著名的示例信息:Hello world. 第一个视图 Hello world视图非常简单. 这些是 ...
- TopK-微博今日热门话题
大纲 TopK on single node TopK on multiple nodes Realtime topK with low QPS Realtime topK with high QPS ...
- IIS8 不能在此路径中使用此配置节。如果在父级别上锁定了该节
问题: 不能在此路径中使用此配置节.如果在父级别上锁定了该节,便会出现这种情况.锁定是默认设置的(overrideModeDefault="Deny"),或者是通过包含 overr ...
- 用 Ipe 画图
如何画一个箭头 首先要了解一个概念:「path object」. Path objects are objects that are formed with lines or curves, exam ...
- 【bzoj2127】happiness 最大流
happiness Time Limit: 51 Sec Memory Limit: 259 MBSubmit: 2579 Solved: 1245[Submit][Status][Discuss ...