CF117C.Cycle

普及+/提高

通过率:0%

时间限制:2.50s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

A tournament is a directed graph without self-loops in which every pair of vertexes is connected by exactly one directed edge. That is, for any two vertexes u and v (u ≠ v) exists either an edge going from u to v, or an edge from v to u.

You are given a tournament consisting of n vertexes. Your task is to find there a cycle of length three.

锦标赛是一个无自环的有向图,其中每对顶点之间恰好存在一条有向边。也就是说,对任意两个顶点 uu 和 vv(u≠vu \ne v),要么存在一条从 uu 指向 vv 的边,要么存在一条从 vv 指向 uu 的边。

你被给定一个包含 nn 个顶点的锦标赛。你的任务是在其中找出一个长度为三的环。

输入格式

The first line contains an integer n (1 ≤ n ≤ 5000). Next n lines contain the adjacency matrix A of the graph (without spaces). A__i, j = 1 if the graph has an edge going from vertex i to vertex j, otherwise A__i, j = 0. A__i, j stands for the j-th character in the i-th line.

It is guaranteed that the given graph is a tournament, that is, A__i, i = 0, A__i, j ≠ A__j, i (1 ≤ i, j ≤ n, i ≠ j).

第一行包含一个整数 nn(1≤n≤50001 \leq n \leq 5000)。接下来的 nn 行包含图的邻接矩阵 AA(各行内无空格)。若图中存在一条从顶点 ii 指向顶点 jj 的边,则 Ai,j=1A_{i,j} = 1;否则 Ai,j=0A_{i,j} = 0。Ai,jA_{i,j} 表示第 ii 行中的第 jj 个字符。

保证所给图是一个竞赛图,即对所有 1≤i,j≤n1 \leq i, j \leq n 且 i≠ji \neq j,均有 Ai,i=0A_{i,i} = 0 且 Ai,j≠Aj,iA_{i,j} \neq A_{j,i}。

输出格式

Print three distinct vertexes of the graph _a_1, _a_2, _a_3 (1 ≤ a__i ≤ n), such that _A__a_1, _a_2 = _A__a_2, _a_3 = _A__a_3, _a_1 = 1, or "-1", if a cycle whose length equals three does not exist.

If there are several solutions, print any of them.

输出图中三个互不相同的顶点 a1,a2,a3a_1, a_2, a_3(其中 1≤ai≤n1 \leq a_i \leq n),使得 Aa1,a2=Aa2,a3=Aa3,a1=1A_{a_1,a_2} = A_{a_2,a_3} = A_{a_3,a_1} = 1;若不存在长度为 3 的环,则输出 -1。

若存在多个解,输出任意一个即可。

输入输出样例

  • 输入#1

    5
    00100
    10000
    01001
    11101
    11000

    输出#1

    1 3 2
  • 输入#2

    5
    01111
    00000
    01000
    01100
    01110

    输出#2

    -1

输入解题思路,AI测评打分。不知道怎么写?

首页