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

18541번 - Milliarium Aureum 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB569823.529%

문제

Roman Empire is vast and, as everybody knows, all roads lead to Rome!

Following the trail of the Last Centurion, professor Melody Song found an ancient map of Roman roads. The exact position of Rome was forgotten long ago, and Melody wants to recover it from the map. There are n cities on the map, numbered from 1 to n, and m roads. Each road is marked as either minor or major.

Major roads were used to travel to Rome and formed a spanning tree, and minor roads were used as alternatives or to travel between other cities. Each road had some fixed width. It is known that major roads were very wide: if we consider two paths from Rome to any other city, one arbitrary path P and another path Q using the major roads, the thinnest road on path P could not be wider than the thinnest road on path Q.

The map found by Melody contains information on every road in Roman Empire, namely its type t and width w. Your task is to help her determine which cities may correspond to Rome according to the map.

입력

The first line of input contains two integers n and m (1 ≤ n, m ≤ 105).

Each of the next m lines contains four integers, ti, ui, vi, and wi, which describe a bidirectional road from city ui to city vi with type ti and width wi (1 ≤ ui, vi ≤ n, 1 ≤ wi ≤ 109). The type is ti = 0 for minor roads and ti = 1 for major roads.

There may be multiple roads between the same pair cities, and there may be roads connecting a city to itself. It is guaranteed though that there is exactly one simple path via major roads between each pair of cities.

출력

On the first line, output an integer k which is number of cities which may be Rome.

On the second line, output k integers in ascending order which are the numbers of those cities.

It is guaranteed that there is at least one such city.

제한

예제 입력 1

4 6
1 1 2 2
1 1 3 2
1 1 4 2
0 2 3 3
0 3 4 3
0 4 2 3

예제 출력 1

1
1

예제 입력 2

3 3
0 2 3 1
1 1 2 2
1 1 3 2

예제 출력 2

3
1 2 3

힌트

출처

Camp > Petrozavodsk Programming Camp > Winter 2019 > Day 7: Oleksandr Kulkov Contest 1, Botan Investment Cup F번

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

출처

대학교 대회

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

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