제출 #770003

#제출 시각아이디문제언어결과실행 시간메모리
770003raysh07철도 요금 (JOI16_ho_t3)C++17
100 / 100
110 ms28996 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define INF (int)1e18 #define f first #define s second mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count()); int n, m, q; const int N = 2e5 + 69; pair <int, int> uv[N], d[N]; int ok[N]; vector <pair<int, int>> adj[N]; int add[N]; bool better (pair<int, int> a, pair<int, int> b){ if (a.f != b.f) return b.f < a.f; else return b.s > a.s; } void Solve() { cin >> n >> m >> q; for (int i = 1; i <= m; i++){ cin >> uv[i].first >> uv[i].second; ok[i] = q + 1; } for (int i = 1; i <= q; i++){ int x; cin >> x; ok[x] = i; } for (int i = 1; i <= m; i++){ // cout << ok[i] << " \n"[i == m]; adj[uv[i].first].push_back({uv[i].second, ok[i]}); adj[uv[i].second].push_back({uv[i].first, ok[i]}); } d[1] = {0, q + 1}; for (int i = 2; i <= n; i++){ d[i] = {INF, 0}; } priority_queue <pair<pair<int, int> , int>> pq; pq.push({{0, q + 1}, 1}); while (!pq.empty()){ auto pi = pq.top(); pq.pop(); int u = pi.second; int ds = -pi.first.first; int tm = pi.first.second; // cout << "TM " << tm << "\n"; for (auto [v, w] : adj[u]){ if (better(d[v], make_pair(ds + 1, min(tm, w)))){ d[v] = make_pair(ds + 1, min(tm, w)); pq.push({{-d[v].first, d[v].second}, v}); } } } for (int i = 1; i <= n; i++){ add[d[i].second]++; } for (int i = 1; i <= q; i++){ add[i] += add[i - 1]; cout << add[i] << "\n"; } } int32_t main() { auto begin = std::chrono::high_resolution_clock::now(); ios_base::sync_with_stdio(0); cin.tie(0); int t = 1; // cin >> t; for(int i = 1; i <= t; i++) { //cout << "Case #" << i << ": "; Solve(); } auto end = std::chrono::high_resolution_clock::now(); auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin); cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...