CF1423A.Wakanda Forever

NOI/NOI+/CTSC

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

In the Kingdom of Wakanda, the 2020 economic crisis has made a great impact on each city and its surrounding area. Cities have made a plan to build a fast train rail between them to boost the economy, but because of the insufficient funds, each city can only build a rail with one other city, and they want to do it together.

Cities which are paired up in the plan will share the cost of building the rail between them, and one city might need to pay more than the other. Each city knows the estimated cost of building their part of the rail to every other city. One city can not have the same cost of building the rail with two different cities.

If in a plan, there are two cities that are not connected, but the cost to create a rail between them is lower for each of them than the cost to build the rail with their current pairs, then that plan is not acceptable and the collaboration won't go on. Your task is to create a suitable plan for the cities (pairing of the cities) or say that such plan doesn't exist.

在瓦坎达王国,2020 年的经济危机对每座城市及其周边地区造成了巨大影响。各城市制定了建设计划,拟在彼此之间修建一条高速列车轨道以振兴经济;但由于资金不足,每座城市最多只能与另一座城市合作修建一条轨道,且该轨道必须由双方共同建设。

计划中配对的城市将共同承担它们之间轨道的建设费用,但其中一座城市可能需要比另一座城市支付更多费用。每座城市均知晓其自身修建通往其他任意一座城市的轨道所需的成本估计值;且对于任一城市而言,它通往不同城市的建设成本互不相同。

若在某项计划中,存在两座尚未配对的城市,而它们彼此之间修建轨道的成本,各自均低于其当前配对城市对应的建设成本,则该计划不可接受,合作将无法进行。你的任务是为这些城市构造一个可行的配对方案(即城市两两配对),或判定这样的方案不存在。

输入格式

First line contains one integer $N ;(2 \leq N \leq 10^3), $ — the number of cities.

Each of the next NN lines contains N−1N-1 integers $A_{i,1}, A_{i,2}, ..., A_{i,i-1}, A_{i,i+1}, ..., A_{i,N}; (1 \leq A_{i,j} \leq 10^9), $ — where Ai,jA_{i,j} represents the cost for city ii to build the rail to city jj. Note that in each line Ai,iA_{i,i} is skipped.

第一行包含一个整数 N  (2≤N≤103)N \;(2 \leq N \leq 10^3),表示城市的数量。

接下来的 NN 行中,每行包含 N−1N-1 个整数 Ai,1,Ai,2,...,Ai,i−1,Ai,i+1,...,Ai,N  (1≤Ai,j≤109)A_{i,1}, A_{i,2}, ..., A_{i,i-1}, A_{i,i+1}, ..., A_{i,N}\; (1 \leq A_{i,j} \leq 10^9),其中 Ai,jA_{i,j} 表示城市 ii 修建通往城市 jj 的铁路所需的成本。注意:每行中均跳过 Ai,iA_{i,i}。

输出格式

Output should contain NN integers O1,O2,...,ONO_{1}, O_{2}, ..., O_N, where OiO_i represents the city with which city ii should build the rail with, or −1-1 if it is not possible to find the stable pairing.

输出应包含 NN 个整数 O1,O2,...,ONO_{1}, O_{2}, ..., O_N,其中 OiO_i 表示城市 ii 应与之修建铁路的城市编号;若无法找到稳定匹配,则 Oi=−1O_i = -1。

输入输出样例

  • 输入#1

    4
    35 19 20
    76 14 75
    23 43 78
    14 76 98

    输出#1

    3
    4
    1
    2
  • 输入#2

    4
    2 5 8
    7 1 12
    4 6 7
    8 4 5

    输出#2

    -1

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

首页