Utopia Relationships

면접 대비

시간 제한1초메모리 제한2048 MB

요약
무방향 그래프의 각 정점이 이웃에게 10000 포인트를 나눠 보내되 각 간선의 양방향 값이 같도록 만들 수 있는지 판정하고, 가능하면 그 값을 출력한다.
난이도

보통10점 중 6점

유형
그래프, 수학, 그리디, 구현
정답자
아직 제출이 없습니다

문제

In the Kingdom of Utopia, society has become highly digitized, even in relationships. The governor has built a massive database system of billions of GPUs to record relationships of its residents. Between any two residents, it is required that if they are acquaintances, they have to be registered in the kingdom’s database. Note that a registered relationship is mutual: if AA is registered to be an acquaintance of BB, then BB is also registered as an acquaintance of AA.

In the last effort to fully digitize relationships, King Aurelius IV proposes “numerical affectionate points”. Every resident of the Utopia Kingdom is given 10,00010\\, 000 affectionate points. The residents are then required to distribute their affectionate points to the other residents that have registered their relationship in the database. For example, if AA has registered to be an acquaintance to BB and CC, AA can distribute 3,0003\\, 000 affectionate points to BB, and 7,0007\\, 000 affectionate points to CC. If AA is not registered to DD, AA can not give DD any affectionate point. Residents can distribute any integral quantity of affection points, from 00 to 10,00010\\, 000 inclusive.

The King wants to make sure that points distribution is fair and equal: if AA gives BB xx affectionate point, then BB must also give AA the same xx affectionate points. Further, a resident must also distribute all of their affectionate points; the sum of all affectionate points that a resident distributes to their acquaintances must be 10,00010\\, 000.

The King gives you the database of registered relationships, and he wants you to figure out if it is possible for the Kingdom to implement this protocol. You must determine if the king’s scheme is possible, and if it is, you must give the King a valid affectionate point distribution.

입력

The first line of input contains two integers nn (2≤n≤1,0002 \le n \le 1\\, 000) and mm (1≤m≤5,0001 \le m \le 5\\, 000), where nn is the number of citizens of Utopia, and mm is the number of registered relationships. The citizens are numbered from 11 to nn.

Each of the next mm lines contains two integers aa and bb (1≤a,b≤n,a≠b1 \le a,b \le n, a \neq b), describing a registered relationship between citizens aa and bb. All relationships will be unique. If aa bb appears in the input, then aa is an acquaintance of bb and bb is an acquaintance of aa, so bb aa will not appear in the input.

출력

If it is possible to distribute Affection Points as the king requires, then output nn lines, each containing nn integers. The number at position (i,j)(i,j) is the number of Affection Points between citizens ii and jj. Note that along the diagonal where i=ji=j, the number of affection points is clearly 00.

If it is not possible to distribute Affection Points as the king requires, simply output −1-1.

예제2

  1. 예제 1

    입력
    5 6
    1 2
    1 3
    2 3
    3 4
    3 5
    5 4
    
    예상 출력
    0 7500 2500 0 0
    7500 0 2500 0 0
    2500 2500 0 2500 2500
    0 0 2500 0 7500
    0 0 2500 7500 0
    
  2. 예제 2

    입력
    6 5
    1 2
    3 1
    3 2
    4 5
    6 5
    
    예상 출력
    -1