#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vi = vector<int>;
const ll INF = 1'000'000'000'000'000'000LL;
int main()
{
int N, K;
cin >> N >> K;
vvll dist(1+N, vll(1+N, INF));
// for(int i = 1; i <= N; i++) dist[i][i] = 0;
vvll has_edge(1+N, vll(1+N, 0));
// vvll edge(1+N, vll(1+N, 0));
vector< pair<int, ll> > edge[1+N];
for(int e = 1; e <= N-1; e++)
{
int a, b, d;
cin >> a >> b >> d;
has_edge[a][b] = has_edge[b][a] = 1;
// dist[a][b] = dist[b][a] = d;
// edge[a][b] = edge[b][a] = 1;
edge[a].push_back({b, d});
edge[b].push_back({a, d});
}
for(int i = 1; i <= N; i++)
{
queue<int> tbv;
tbv.push(i);
dist[i][i] = 0;
while(!tbv.empty())
{
int u = tbv.front();
tbv.pop();
for(auto q: edge[u])
{
int v = q.first;
ll w = q.second;
if(dist[i][v] < INF) continue;
dist[i][v] = dist[i][u] + w;
tbv.push(v);
}
}
}
// for(int k = 1; k <= N; k++)
// for(int i = 1; i <= N; i++)
// for(int j = 1; j <= N; j++)
// dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
vi par(1+N, -1);
for(int i = 2; i <= N; i++)
{
for(int j = 1; j <= N; j++)
{
if(j == i) continue;
if(dist[1][i] == dist[1][j] + dist[j][i] && has_edge[i][j] == 1)
{
par[i] = j;
break;
}
}
}
vector<pair<ll, int> > V;
for(int i = 1; i <= N; i++) V.push_back({dist[1][i], i});
sort(V.begin(), V.end());
vi res;
reverse(V.begin(), V.end());
vi covered(1+N, 0);
// if(N >= 100) while(1);
for(auto q: V)
{
int u = q.second;
// while(N >= 100);
if(covered[u]) continue;
int v = u;
while(v != 1 && dist[par[v]][u] <= K)
{
v = par[v];
// if(v == -1) while(1);
}
res.push_back(v);
for(int i = 1; i <= N; i++)
covered[i] |= (dist[v][i] <= K);
if(N >= 100) while(1);
}
cout << int(res.size()) << '\n';
for(int r: res) cout << r << ' ';
cout << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
369 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
232 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
0 ms |
204 KB |
Output is correct |
24 |
Correct |
0 ms |
204 KB |
Output is correct |
25 |
Correct |
0 ms |
204 KB |
Output is correct |
26 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
369 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3073 ms |
83780 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
353 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |