RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
COCI00677

Ministarstvo

Unrated 레이팅 미적용
난이도
1s
시간 제한
1024MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

Croatian Olympiad in Informatics
April \(28^{st}\) 2024
After a successful career in a party we won’t name, Pero got a job at the Ministry of Tourism. Pero
oversees a network of \(N\) cities, labeled with numbers from 1 to \(N\), where there is exactly one, o\(ne-wa\)y
road between each pair of cities. In order to increase revenue, he has decided to introduce permits for
traffic. Pero would prefer to introduce a special permit for each road, but that would alert his superiors.
Therefore, he will introduce \(K\) different permits, labeled from 1 to \(K\), and possession of a specific permit
will be required to travel on each road.
To still ensure substantial revenue, Pero will settle for the following property.
• For each city \(v\), there is some city \(u\), such that it is not possible to travel from city \(v\) to city \(u\) with
just one permit.
Pero asks for your help to determine the minimum \(K\) such that there exists an assignment of permits
with the desired property, if such an assignment exists! If no such assignment exists, outp\(ut -1\).

제약

In all subtasks, \(2 \le N \le 1000\). In each subtask, 15% of the points come from only deciding whether such
an assignment exists or not. For these points, if you don’t outp\(ut -1\), you need to output some assignment,
but it doesn’t have to satisfy Pero’s desired property.
Subtask
Score
Constraints
1
20
\(N \le 5\)
2
80
No additional constraints.
Croatian Olympiad in Informatics
April \(28^{st}\) 2024

입력 형식

The first line contains a positive integer \(N\).
The \(i-th\) of the following \(N\) lines contains \(N\) numbers \(a\)i,j where \(a\)i,\(j = 1\) if there is a road from city \(i\) to
city \(j\). Note that \(a_{i,i} = 0\) and for \(i\)̸ = \(j\), exactly one of the numbers \(a_{i,j}\) and \(a_{j,i}\) is n\(on-ze\)ro.

출력 형식

If there is no assignment with the desired property, outp\(ut -1\) in the first and only line.
Otherwise, output the minimum positive integer \(K\) in the first line.
In the following \(N\) lines, output the description of the assignment.
In the \(i-th\) line, output \(N\) numbers \(b_{i,j}\) where if \(a_{i,j} = 0\), then \(b_{i,j} = 0\), otherwise \(1 \le b_{i,j} \le K\) indicating
which permit is required for traveling on that road.

예제 1
입력
3
0 1 0
0 0 1
1 0 0
출력
3
0 1 0
0 0 2
3 0 0
예제 2
입력
3
0 1 1
0 0 1
0 0 0
출력
-1
예제 3
입력
4
0 1 0 1
0 0 1 1
1 0 0 0
0 0 1 0
출력
3
0 1 0 1
0 0 2 3
3 0 0 0
0 0 2 0
설명

Explanation for the third sample test:
Roads requiring the first permit are marked in red, the second permit in blue, and the third permit in
green.
From city 1, it is not possible to reach city 3 using just one permit.
From city 2, it is not possible to reach city 1 using just one permit.
From city 3, it is not possible to reach city 2 using just one permit.
From city 4, it is not possible to reach city 1 using just one permit.

문제 정보

생성자가 기록되지 않았습니다.

출처 COCI 2023/2024 Olympiad

평가 및 의견

Ministarstvo

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Ministarstvo

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8