Submission #500694

#TimeUsernameProblemLanguageResultExecution timeMemory
500694blueFirefighting (NOI20_firefighting)C++17
Compilation error
0 ms0 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) { int u = q.second; 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++) if(dist[i][v] <= K) covered[i] = 1; } cout << int(res.size()) << '\n'; for(int r: res) cout << r << ' '; cout << '\n'; }

Compilation message (stderr)

Firefighting.cpp: In function 'int main()':
Firefighting.cpp:96:17: error: 'v' was not declared in this scope
   96 |     for(auto q: v)
      |                 ^
Firefighting.cpp:102:13: error: redeclaration of 'int v'
  102 |         int v = u;
      |             ^
Firefighting.cpp:96:17: note: '<typeprefixerror>v' previously declared here
   96 |     for(auto q: v)
      |                 ^