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.
锦标赛是一个无自环的有向图,其中每对顶点之间恰好存在一条有向边。也就是说,对任意两个顶点 u 和 v(u=v),要么存在一条从 u 指向 v 的边,要么存在一条从 v 指向 u 的边。
你被给定一个包含 n 个顶点的锦标赛。你的任务是在其中找出一个长度为三的环。
输入格式
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).
第一行包含一个整数 n(1≤n≤5000)。接下来的 n 行包含图的邻接矩阵 A(各行内无空格)。若图中存在一条从顶点 i 指向顶点 j 的边,则 Ai,j=1;否则 Ai,j=0。Ai,j 表示第 i 行中的第 j 个字符。
保证所给图是一个竞赛图,即对所有 1≤i,j≤n 且 i=j,均有 Ai,i=0 且 Ai,j=Aj,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,a3(其中 1≤ai≤n),使得 Aa1,a2=Aa2,a3=Aa3,a1=1;若不存在长度为 3 的环,则输出 -1。
若存在多个解,输出任意一个即可。
输入输出样例
输入#1
5 00100 10000 01001 11101 11000
输出#1
1 3 2
输入#2
5 01111 00000 01000 01100 01110
输出#2
-1
输入解题思路,AI测评打分。不知道怎么写?