Utopia Relationships
면접 대비시간 제한1초메모리 제한2048 MB
무방향 그래프의 각 정점이 이웃에게 10000 포인트를 나눠 보내되 각 간선의 양방향 값이 같도록 만들 수 있는지 판정하고, 가능하면 그 값을 출력한다.
문제
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 is registered to be an acquaintance of , then is also registered as an acquaintance of .
In the last effort to fully digitize relationships, King Aurelius IV proposes “numerical affectionate points”. Every resident of the Utopia Kingdom is given 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 has registered to be an acquaintance to and , can distribute affectionate points to , and affectionate points to . If is not registered to , can not give any affectionate point. Residents can distribute any integral quantity of affection points, from to inclusive.
The King wants to make sure that points distribution is fair and equal: if gives affectionate point, then must also give the same 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 .
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 () and (), where is the number of citizens of Utopia, and is the number of registered relationships. The citizens are numbered from to .
Each of the next lines contains two integers and (), describing a registered relationship between citizens and . All relationships will be unique. If appears in the input, then is an acquaintance of and is an acquaintance of , so will not appear in the input.
출력
If it is possible to distribute Affection Points as the king requires, then output lines, each containing integers. The number at position is the number of Affection Points between citizens and . Note that along the diagonal where , the number of affection points is clearly .
If it is not possible to distribute Affection Points as the king requires, simply output .