首页 > 其他 > 详细

CodeForces-939A

时间:2019-08-16 00:27:25      阅读:91      评论:0      收藏:0      [点我收藏+]

链接:

https://vjudge.net/problem/CodeForces-939A

题意:

As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are n planes on Earth, numbered from 1 to n, and the plane with number i likes the plane with number fi, where 1?≤?fi?≤?n and fi?≠?i.

We call a love triangle a situation in which plane A likes plane B, plane B likes plane C and plane C likes plane A. Find out if there is any love triangle on Earth.

思路:

刚开始以为拓扑排序,想了下直接找就行了,判断i 和 F[F[F[i]]].

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
//#include <memory.h>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
#include <stack>
#include <string>
#include <assert.h>
#define MINF 0x3f3f3f3f
using namespace std;
typedef long long LL;

const int MAXN = 5e3+10;
int F[MAXN];
int n;

int main()
{
    cin >> n;
    for (int i = 1;i <= n;i++)
        cin >> F[i];
    bool flag = false;
    for (int i = 1;i <= n;i++)
        if (F[F[F[i]]] == i)
            flag = true;
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}

CodeForces-939A

原文:https://www.cnblogs.com/YDDDD/p/11361067.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!