제출 #553194

#제출 시각아이디문제언어결과실행 시간메모리
553194Tien_NoobEvacuation plan (IZhO18_plan)C++17
41 / 100
4050 ms31852 KiB
//Make CSP great again //Vengeance #include <bits/stdc++.h> #define TASK "TESTCODE" #define Log2(x) 31 - __builtin_clz(x) using namespace std; const int N = 1e5; priority_queue< pair<int, int>, deque<pair<int, int> > , greater<pair<int, int> > > PQ; vector<pair<int, int> > Adj[N + 1]; int n, m, d[N + 1], id[N + 1], res[N + 1], lab[N + 1], q; map<int, int> dp[N + 1]; void read() { cin >> n >> m; for (int i = 1; i <= m; ++ i) { int u, v, w; cin >> u >> v >> w; Adj[u].push_back({v, w}); Adj[v].push_back({u, w}); } memset(d, 0x3f, sizeof(d)); memset(lab, -1, sizeof(lab)); int k; cin >> k; for (int i = 1; i <= k; ++ i) { int u; cin >> u; d[u] = 0; PQ.push({0, u}); } cin >> q; for (int i = 1; i <= q; ++ i) { int u, v; cin >> u >> v; dp[u][i] = 1; dp[v][i] = 1; } } int FindSet(int u) { return lab[u] < 0 ? u : lab[u] = FindSet(lab[u]); } void Unite(int r, int s, int w) { r = FindSet(r); s = FindSet(s); if (r == s) { return ; } if (lab[r] < lab[s]) { swap(r, s); } lab[r] += lab[s]; lab[s] = r; if (dp[s].size() < dp[r].size()) { swap(dp[r], dp[s]); } for (auto p : dp[s]) { if (dp[r][p.first] == 1) { res[p.first] = w; dp[r].erase(p.first); } else { ++dp[r][p.first]; } } dp[s].clear(); } void Dijkstra() { while(!PQ.empty()) { pair<int, int> p = PQ.top(); PQ.pop(); if (d[p.second] != p.first) { continue; } int u = p.second; for (auto p : Adj[u]) { int v = p.first, w = p.second; if (d[v] > d[u] + w) { d[v] = d[u] + w; PQ.push({d[v], v}); } } } } void solve() { Dijkstra(); iota(id + 1, id + n + 1, 1); sort(id + 1, id + n + 1, [&](const int & x, const int & y) { return d[x] < d[y]; }); for (int i = n; i >= 1; -- i) { int u = id[i]; for (auto p : Adj[u]) { int v = p.first; if (d[v] >= d[u]) { Unite(u, v, d[u]); } } } for (int i = 1; i <= q; ++ i) { cout << res[i] << '\n'; } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); if (fopen(TASK".INP", "r")) { freopen(TASK".INP", "r", stdin); //freopen(TASK".OUT", "w", stdout); } int t = 1; bool typetest = false; if (typetest) { cin >> t; } for (int __ = 1; __ <= t; ++ __) { //cout << "Case " << __ << ": "; read(); solve(); } }

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

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