제출 #1044742

#제출 시각아이디문제언어결과실행 시간메모리
1044742vjudge1Evacuation plan (IZhO18_plan)C++17
100 / 100
334 ms59620 KiB
#include <bits/stdc++.h> #define faster cin.tie(0)->sync_with_stdio(0); #define task "D" #define ll long long #define ld long double #define pii pair<int, int> #define pll pair<ll, ll> #define pdd pair<double, double> #define fi first #define se second #define FOR(i, a, b) for(int i = a; i <= b; ++i) #define FOD(i, a, b) for(int i = a; i >= b; --i) #define FOU(a, b) for(auto& a : b) #define pb push_back #define BIT(x, i) ((x >> i) & 1) #define oo 1e9 #define OO 1e18 using namespace std; const int N = 1e5 + 5; ll n, m, x, y, w, k, q; ll a[N], p[N], parent[N], s[N], id[N]; vector<pll> adj[N]; set<ll> sz[N]; ll dist[N]; bool mark[N]; bool cmp(ll &a, ll &b) { return dist[a] > dist[b]; } void dijstra() { FOR(i, 1, n) dist[i] = OO; priority_queue<pll, vector<pll>, greater<pll>> pq; FOR(i, 1, k) { dist[a[i]] = 0; pq.push({0, a[i]}); } while(!pq.empty()) { ll u = pq.top().se; pq.pop(); if(mark[u]) continue; mark[u] = 1; FOU(v, adj[u]) { ll it = v.fi; ll w = v.se; if(dist[it] > dist[u] + w) { dist[it] = dist[u] + w; pq.push({dist[it], it}); } } } } ll find_set(ll &u) { if(u == parent[u]) return u; return parent[u] = find_set(parent[u]); } void union_set(ll u, ll v) { u = find_set(u); v = find_set(v); if(u == v) return; if(s[u] < s[v]) swap(u, v); parent[v] = u; s[u] += s[v]; FOU(it, sz[v]) { if(sz[u].find(it) != sz[u].end()) { sz[u].erase(it); p[it] = w; } else { sz[u].insert(it); } } } int main() { faster if(fopen(task ".inp", "r")) { freopen(task ".inp", "r", stdin); freopen(task ".out", "w", stdout); } cin >> n >> m; while(m--) { cin >> x >> y >> w; adj[x].pb({y, w}); adj[y].pb({x, w}); } cin >> k; FOR(i, 1, k) cin >> a[i]; dijstra(); cin >> q; FOR(i, 1, q) { cin >> x >> y; sz[x].insert(i); sz[y].insert(i); } FOR(i, 1, n) { id[i] = i; parent[i] = i; s[i] = i; } sort(id + 1, id + n + 1, cmp); memset(mark, 0, sizeof mark); FOR(i, 1, n) { x = id[i]; mark[x] = 1; w = dist[x]; FOU(it, adj[x]) { y = it.fi; if(mark[y]) { union_set(x, y); } } } FOR(i, 1, q) { cout << p[i] << "\n"; } return 0; }

컴파일 시 표준 에러 (stderr) 메시지

plan.cpp: In function 'int main()':
plan.cpp:89:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   89 |         freopen(task ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
plan.cpp:90:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   90 |         freopen(task ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#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...