제출 #552296

#제출 시각아이디문제언어결과실행 시간메모리
552296Soul234Evacuation plan (IZhO18_plan)C++14
100 / 100
681 ms58048 KiB
#include<bits/stdc++.h> using namespace std; void DBG() { cerr << "]\n"; } template<class H, class... T> void DBG(H h, T... t) { cerr << h; if(sizeof...(t)) cerr << ", "; DBG(t...); } #ifdef LOCAL #define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__) #else #define dbg(...) 0 #endif // LOCAL #define FOR(i,a,b) for(int i = (a) ; i<(b) ; i++) #define F0R(i,a) FOR(i,0,a) #define ROF(i,a,b) for(int i = (b)-1 ; i>=(a) ; i--) #define R0F(i,a) ROF(i,0,a) #define each(e,a) for(auto &e : (a)) #define sz(v) (int)(v).size() #define all(v) (v).begin(),(v).end() #define rall(v) (v).rbegin(),(v).rend() #define pb push_back #define tcT template<class T #define nl "\n" using ll = long long; using vi = vector<int>; using pi = pair<int,int>; using str = string; tcT> using V = vector<T>; tcT> using pqg = priority_queue<T,vector<T>,greater<T>>; void setIO(string NAME = "") { cin.tie(0)->sync_with_stdio(0); if(sz(NAME)) { freopen((NAME + ".inp").c_str(),"r",stdin); freopen((NAME + ".out").c_str(),"w",stdout); } } tcT> bool ckmin(T&a, const T&b) { return b < a ? a = b, 1 : 0; } const int MX = 1e5+5, LG = 18; int N, M, K, Q; ll dist[MX], ans[MX]; V<pi> adj[MX], eds; set<int> s[MX]; struct UF { vi e; UF(int n) : e(n, -1) {} int find(int x) { return e[x] < 0 ? x : e[x] = find(e[x]); } bool sameSet(int a, int b) { return find(a) == find(b); } bool join(int a, int b, ll w) { a = find(a), b = find(b); if(a == b) return false; if(sz(s[a]) < sz(s[b])) swap(a,b); each(e, s[b]) { if(s[a].count(e)) { ans[e] = w; s[a].erase(e); } else s[a].insert(e); } e[a] += e[b], e[b] = a; return true; } }; void solve() { cin>>N>>M; F0R(i,M) { int u,v,w; cin>>u>>v>>w; adj[u].pb({v,w}); adj[v].pb({u,w}); eds.pb({u,v}); } memset(dist, 0x3f, sizeof dist); cin>>K; pqg<pair<ll,int>> pq; F0R(i,K) { int u; cin>>u; pq.push({dist[u] = 0, u}); } while(sz(pq)) { ll du = pq.top().first; int u = pq.top().second; pq.pop(); if(du != dist[u]) continue; each(ed, adj[u]) { int v = ed.first; ll dv = du + ed.second; if(ckmin(dist[v], dv)) pq.push({dist[v], v}); } } cin>>Q; F0R(i,Q) { int u,v; cin>>u>>v; s[u].insert(i); s[v].insert(i); } UF dsu(N+1); sort(all(eds), [&](const pi&a, const pi&b){ return min(dist[a.first], dist[a.second]) > min(dist[b.first], dist[b.second]); }); F0R(i,sz(eds)) { dsu.join(eds[i].first, eds[i].second, min(dist[eds[i].first], dist[eds[i].second])); } F0R(i,Q) cout << ans[i] << nl; } int main() { setIO(); int t=1; //cin>>t; while(t-->0) { solve(); } return 0; }

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

plan.cpp: In function 'void setIO(std::string)':
plan.cpp:37:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |         freopen((NAME + ".inp").c_str(),"r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
plan.cpp:38:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         freopen((NAME + ".out").c_str(),"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...