Logo
(追記) (追記ここまで)

9330번 - Seven Kingdoms 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
9 초 128 MB70201737.778%

문제

Jon Dayne is the ruler of a huge country called Seven Kingdoms. He has two sisters, Arya and Sansa, and wants to give some cities of Seven Kingdoms to them. He will rule the remaining cities or if no city remains, goes to the Wall, a colossal fortification along the northern border of the Seven Kingdoms, to be the Lord commander. Arya is the Lady of Winterfell and Sansa is the Lady of King’s Landing. The cities in Seven Kingdoms (including Winterfell and King’s Landing) are connected to each other with a network of roads (although some cities may be disconnected from the other cities, because they are either located on an island or they are currently at war with these other cities). There is no direct road between Winterfell and King’s Landing and they do not share a common neighbour city.

Jon wants to assign a collection of cities to each one of his sisters such that each city in a collection is connected with a direct road to all other cities in that collection and the remaining cities, not in these two collections, are also connected with a direct road to each other. The collection assigned to Arya must include Winterfell and the collection assigned to Sansa must include King’s Landing. Jon needs your help to determine whether this is possible and if this is possible, you should tell him the cities in each collection.

입력

The input consists of a single test case. The first line contains two integers n and m, where n (2 ≤ n ≤ 2000) is the number of cities, m is the number of roads. Each of the next m lines contains two integers xi and yi (1 ≤ xi, yi ≤ n) describing one road, where xi and yi are the distinct cities the road connects. Winterfell is city 1 and King’s Landing is city 2 in the road network.

출력

If it is not possible to partition the cities in the way explained, display the word impossible. Otherwise, display two lines: the first containing the cities in the collection assigned to Arya and the second containing the collection of cities assigned to Sansa. If there are many such collections, any one of them is acceptable.

제한

예제 입력 1

9 11
1 4
5 4
1 5
6 2
6 7
7 2
3 8
3 9
8 9
6 8
5 9

예제 출력 1

1 4 5
2 6 7

힌트

출처

ICPC > Regionals > North America > Rocky Mountain Regional > 2013 Rocky Mountain Regional Contest B번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /