2029: [USACO 2024 February Contest Gold] Problem 1. Bessla Motors

文件提交:无需freopen 内存限制:512 MB 时间限制:3.000 S
评测方式:普通裁判 命题人:
提交:3 解决:0

题目描述

Farmer John would like to promote his line of Bessla electric tractors by showcasing Bessla's network of charging stations. He has identified N (2N5104) points of interest labeled 1N, of which the first C (1C<N) are charging stations and the remainder are travel destinations. These points of interest are interconnected by M (1M105) bidirectional roads, the i-th of which connects distinct points ui and vi (1ui,viN) and has length i miles (1i109).

A Bessla can travel up to 2R miles (1R109) on a single charge, allowing it to reach any destination within R miles of a charging station. A destination is deemed well-connected if it is reachable from at least K (1K10) distinct charging stations. Your task is to assist Farmer John in identifying the set of well-connected travel destinations.

输入

The first line contains five space-separated integers NMCR, and K. Each of the following M lines contains three space-separated integers uivi, and i such that uivi.

The charging stations are labeled 1,2,,C. The remaining points of interest are all travel destinations.

输出

First, output the number of well-connected travel destinations on a single line. Then, list all well-connected travel destinations in ascending order, each on a separate line.

样例输入

3 3 1 4 1
1 2 3
1 3 5
2 3 2

样例输出

1
2

提示

We have one charging station at 1. From this charging station, we can reach point 2 (since it is distance 3 away from 1), but not point 3 (since it is distance 5 away from 1). Thus, only point 2 is well-connected.

SAMPLE INPUT:

4 3 2 101 2

1 2 1

2 3 100

1 4 10

SAMPLE OUTPUT:

2

3

4

We have charging stations at 1 and 2, and both points 3 and 4 are within distance 101 of both 1 and 2. Thus, both points 3 and 4 are well-connected.

SAMPLE INPUT:

4 3 2 100 2

1 2 1

2 3 100

1 4 10

SAMPLE OUTPUT:

1

4

SCORING:

  • Inputs 4 and 5: K=2 and N500 and M1000.
  • Inputs 6 and 7: K=2.
  • Inputs 8-15: No additional constraints.

来源/分类