Love Triangle

Descriptions:

正如你所知道的,没有男性飞机也没有女性飞机。然而,地球上的每一个平面都喜欢另一个平面。地球上有n个平面,编号从1到n,编号i的平面喜欢编号fi的平面,其中1≤fi≤n且fi≠i。

我们把平面A喜欢平面B,平面B喜欢平面C,平面C喜欢平面a的情况称为“三角恋”。

Input

第一行包含一个整数n(2≤n≤5000)——面数。

第二行包含n个整数f1 f2…, fn(1≤fi≤n, fi≠i),表示第i个平面喜欢第fi个平面。

Output

输出"YES"如果地球上有一个由平面组成的三角恋。否则,输出"NO"。

Examples

Input
5
2 4 5 1 3
Output
YES
Input
5
5 5 5 5 1
题目链接
 
水题 模拟吧
 
AC代码
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define Mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
#define Maxn 1100000
using namespace std;
int n;
int a[Maxn];
int main()
{
cin>>n;
for(int i=;i<=n;i++)
cin>>a[i];
int f=;
for(int i=;i<=n;i++)
{
int cnt=;//三角恋 当前次数为1
int init=i;
int x=i;
int y;
while(cnt<=&&x<=n)
{
y=a[x];
x=y;
cnt++;
}
if(x==init)
{
f=;
cout<<"YES"<<endl;
break;
}
}
if(f==)
cout<<"NO"<<endl; }

【CodeForces - 939A】Love Triangle(模拟)的更多相关文章

  1. Codeforces 738D. Sea Battle 模拟

    D. Sea Battle time limit per test: 1 second memory limit per test :256 megabytes input: standard inp ...

  2. Codeforces 626A Robot Sequence(模拟)

    A. Robot Sequence time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...

  3. CodeForces - 589D(暴力+模拟)

    题目链接:http://codeforces.com/problemset/problem/589/D 题目大意:给出n个人行走的开始时刻,开始时间和结束时间,求每个人分别能跟多少人相遇打招呼(每两人 ...

  4. Codeforces 767B. The Queue 模拟题

    B. The Queue time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...

  5. Codeforces 939A题,B题(水题)

    题目链接:http://codeforces.com/problemset/problem/939/A A题 A. Love Triangle time limit per test 1 second ...

  6. hdu4488 Faulhaber’s Triangle(模拟题)

    Faulhaber’s Triangle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  7. Codeforces 704A Thor 队列模拟

    题目大意:托尔有一部手机可执行三种操作 1.x APP产生一个新消息 2.读取x App已产生的所有消息 3.读取前t个产生的消息 问每次操作后未读取的消息的数量 题目思路: 队列模拟,坑点在于竟然卡 ...

  8. CodeForces - 939A,解题报告

    题意:给出一个n个点有向图,问是否存在三个点,这三个点构成一个回路.n<=5000 模拟即可. 注意是必须三个点 多了居然不行. import java.util.*; public class ...

  9. Vasya And The Mushrooms CodeForces - 1016C (前缀和模拟)

    大意: 给定2*n的矩阵, 每个格子有权值, 走到一个格子的贡献为之前走的步数*权值, 每个格子只能走一次, 求走完所有格子最大贡献. 沙茶模拟打了一个小时总算打出来了 #include <io ...

随机推荐

  1. BZOJ4886 [Lydsy1705月赛]叠塔游戏[基环树]

    很妙的一道题. 由于本人过于zz,不会这道题,通过厚颜无耻翻阅题解无数终于懂了这道题,所以这里转载一位神仙的blog. 没有看懂?没事,再来一篇. 这题个人认为主要在于转化题意和建图,这两点想通了应该 ...

  2. 编辑器 --- Visual Studio Code 英文界面转换成中文(简体)

    打开编辑器 同时按下Ctrl+Shift+P打开命令面板: 之后输入"config"筛选可用命令表,最后选择配置语言命令进行选择或安装插件

  3. 一个列表实现__iter__和__next__方法的例子

    x = ['厉智','陈培昌','程劲','徐晓冬'].__iter__() #这非得这么写不可,否则无法调用下面的__next__()方法,切记! print(x.__next__()) print ...

  4. Codeforces Round #589 (Div. 2) B. Filling the Grid

    链接: https://codeforces.com/contest/1228/problem/B 题意: Suppose there is a h×w grid consisting of empt ...

  5. 04 DRF内容回顾、用户登录 (含跨域) (vuex vue-cookie)、用户认证 (Auth认证)(拦截器)

    1.内容回顾 1.视图中常见的继承 2.频率访问控制源码 3.序列化,反序列化 2.初始化代码 1.后端代码:AuthView (1)目录结构 (2)urls (3)view (4)注释掉cors ( ...

  6. 2019icpc沈阳网络赛 D Fish eating fruit 树形dp

    题意 分别算一个树中所有简单路径长度模3为0,1,2的距离和乘2. 分析 记录两个数组, \(dp[i][k]\)为距i模3为k的子节点到i的距离和 \(f[i][k]\)为距i模3为k的子节点的个数 ...

  7. 爬虫之urllib库使用

    请求方法request import urllib.request url = "https://blog.csdn.net/fengxinlinux/article/details/772 ...

  8. reduce()之js与python

    最近在自学python基础,发现很多js中的内置函数python中都存在,甚至比js更加简洁,下面说一下reduce()在js和python中的用法,做个对比便于记忆. reduce()简介: red ...

  9. 2016 Multi-University Training Contest 1 部分题解

    第一场多校,出了一题,,没有挂零还算欣慰. 1001,求最小生成树和,确定了最小生成树后任意两点间的距离的最小数学期望.当时就有点矛盾,为什么是求最小的数学期望以及为什么题目给了每条边都不相等的条件. ...

  10. session机制、cookie机制

    一.Cookie机制 在web程序中是使用HTTP协议来传输数据的,因为http是无状态协议,一旦数据交换完毕,客户端和服务器端的连接就会关闭,再次交换数据需要建立新的连接,所以无法实现会话跟踪,co ...