CF323B.Tournament-graph

提高+/省选-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

In this problem you have to build tournament graph, consisting of n vertices, such, that for any oriented pair of vertices (v, u) (v ≠ u) there exists a path from vertex v to vertex u consisting of no more then two edges.

A directed graph without self-loops is a tournament, if there is exactly one edge between any two distinct vertices (in one out of two possible directions).

本题要求构造一个包含 nn 个顶点的竞赛图,使得对任意一对有序顶点 (v, u)(v,\,u)(其中 v≠uv \ne u),均存在一条从顶点 vv 到顶点 uu 的有向路径,且该路径所含边数不超过两条。

一个无自环的有向图称为竞赛图,当且仅当对任意两个不同的顶点,二者之间恰好存在一条有向边(即两个可能方向中仅取其一)。

输入格式

The first line contains an integer n (3 ≤ n ≤ 1000), the number of the graph's vertices.

第一行包含一个整数 nn(3 ≤ n ≤ 10003 \leq n \leq 1000),表示图的顶点数。

输出格式

Print -1 if there is no graph, satisfying the described conditions.

Otherwise, print n lines with n integers in each. The numbers should be separated with spaces. That is adjacency matrix a of the found tournament. Consider the graph vertices to be numbered with integers from 1 to n. Then a__v, u = 0, if there is no edge from v to u, and a__v, u = 1 if there is one.

As the output graph has to be a tournament, following equalities must be satisfied:

  • a__v, u + a__u, v = 1 for each v, u (1 ≤ v, u ≤ n; v ≠ u);
  • a__v, v = 0 for each v (1 ≤ v ≤ n).

如果不存在满足所述条件的图,则输出 -1。

否则,输出 n 行,每行包含 n 个整数,各数之间用空格分隔。即输出所找到的竞赛图(tournament)的邻接矩阵 a。设图的顶点编号为 1 到 n 的整数,则当不存在从顶点 v 指向顶点 u 的有向边时,a_{v,u} = 0;当存在该有向边时,a_{v,u} = 1。

由于输出图必须是一个竞赛图,以下等式必须成立:

  • 对任意 v, u(1 ≤ v, u ≤ n 且 v ≠ u),有 a_{v,u} + a_{u,v} = 1;
  • 对任意 v(1 ≤ v ≤ n),有 a_{v,v} = 0。

输入输出样例

  • 输入#1

    3

    输出#1

    0 1 0
    0 0 1
    1 0 0
  • 输入#2

    4

    输出#2

    -1

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

首页