Submission #500688

#TimeUsernameProblemLanguageResultExecution timeMemory
500688blueFirefighting (NOI20_firefighting)C++17
14 / 100
3085 ms1048580 KiB
#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) { if(N >= 100) while(1); 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]; res.push_back(v); for(int i = 1; i <= N; i++) covered[i] |= (dist[v][i] <= K); } cout << int(res.size()) << '\n'; for(int r: res) cout << r << ' '; cout << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...