제출 #1199233

#제출 시각아이디문제언어결과실행 시간메모리
1199233gugugEvacuation plan (IZhO18_plan)C++17
41 / 100
4093 ms28436 KiB
#pragma GCC optimize("Ofast,unroll-loops") #include <bits/stdc++.h> using namespace std; #define pii pair<int, int> #define iii tuple<int, int, int> int n, m, k, q, parent[100001], sz[100001], ans[100001]; iii queries[100000]; vector<pii> adj[100001]; vector<int> aadj[100001]; pii dist[100001]; bool flag[100001]; priority_queue<pii, vector<pii>, greater<pii>> pq; int find(int x) { if (x == parent[x]) return x; return parent[x] = find(parent[x]); } void unite(int u, int v) { u = find(u), v = find(v); if (u == v) return; if (sz[u] > sz[v]) { sz[u] += sz[v]; parent[v] = u; } else { sz[v] += sz[u]; parent[u] = v; } } int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { parent[i] = i; sz[i] = 1; dist[i] = {0x3f3f3f3f, i}; } for (int i = 1; i <= m; i++) { int u, v, w; scanf("%d %d %d", &u, &v, &w); adj[u].push_back({v, w}); adj[v].push_back({u, w}); } scanf("%d", &k); for (int i = 0; i < k; i++) { int g; scanf("%d", &g); pq.push({0, g}); dist[g].first = 0; } while (!pq.empty()) { auto [d, u] = pq.top(); pq.pop(); if (flag[u]) continue; flag[u] = 1; for (auto [v, w]: adj[u]) if (!flag[v] && dist[v].first > dist[u].first + w) { dist[v].first = dist[u].first + w; pq.push({dist[v].first, v}); } } sort(dist + 1, dist + n + 1, greater<pii>()); scanf("%d", &q); for (int i = 0; i < q; i++) { auto& [a, b, c] = queries[i]; scanf("%d %d", &a, &b); c = i; } for (int i = 1; i <= n; i++) { auto [d, u] = dist[i]; for (auto [v, w]: adj[u]) aadj[v].push_back(u); for (auto v: aadj[u]) unite(u, v); for (int j = 0; j < q; j++) { auto [a, b, c] = queries[j]; if (find(a) == find(b) && !ans[c]) ans[c] = d; } } for (int i = 0; i < q; i++) printf("%d\n", ans[i]); }

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

plan.cpp: In function 'int main()':
plan.cpp:33:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |   scanf("%d%d", &n, &m);
      |   ~~~~~^~~~~~~~~~~~~~~~
plan.cpp:40:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |     int u, v, w; scanf("%d %d %d", &u, &v, &w);
      |                  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
plan.cpp:44:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |   scanf("%d", &k);
      |   ~~~~~^~~~~~~~~~
plan.cpp:46:17: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |     int g; scanf("%d", &g);
      |            ~~~~~^~~~~~~~~~
plan.cpp:59:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |   scanf("%d", &q);
      |   ~~~~~^~~~~~~~~~
plan.cpp:62:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |     scanf("%d %d", &a, &b);
      |     ~~~~~^~~~~~~~~~~~~~~~~
#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...