제출 #571460

#제출 시각아이디문제언어결과실행 시간메모리
571460Doanxem99Evacuation plan (IZhO18_plan)C++14
10 / 100
4054 ms73660 KiB
#include <bits/stdc++.h> using namespace std; #define ar array< long long , 2> #define arr array< long long , 3> #define MASK(i) (1 << (i)) #define BIT(x, i) (((x) >> (i)) & 1) const long long MAX = 1e6 + 1000; long long d[MAX], n, m, x, y, z, npp[MAX], k, q; bool NPP[MAX]; vector < ar > A[MAX]; void DFS(long long x) { for (ar y : A[x]) { if (!NPP[y[0]] && d[y[0]] > d[x] + y[1]) { d[y[0]] = d[x] + y[1]; DFS(y[0]); } } } long long BFS(long long s, long long t) { vector < long long > dd; dd.resize(n + 100, 0); priority_queue< ar > QU; QU.push({d[s], s}); while (!QU.empty()) { ar x = QU.top(); QU.pop(); if (x[1] == t) return x[0]; for (ar y : A[x[1]]) { if (dd[y[0]] < min(d[y[0]], x[0])) { dd[y[0]] = min(d[y[0]], x[0]); QU.push({dd[y[0]], y[0]}); } } } } void BFS2() { queue< long long > QU; for (long long i = 1; i <= k; i++) { QU.push(npp[i]); } while (!QU.empty()) { long long x = QU.front(); QU.pop(); for (ar y : A[x]) { if (d[y[0]] > d[x] + y[1]) { d[y[0]] = d[x] + y[1]; QU.push(y[0]); } } } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; memset(d, 0x3f, sizeof d); for (long long i = 1; i <= m; i++) { cin >> x >> y >> z; A[x].push_back({y, z}); A[y].push_back({x, z}); } cin >> k; for (long long i = 1; i <= k; i++) { cin >> npp[i]; NPP[npp[i]] = 1; d[npp[i]] = 0; } BFS2(); //for (long long i = 1; i <= n; i++) cout << d[i] << " " ; cin >> q; for (long long i = 1; i <= q; i++) { cin >> x >> y; if (NPP[x] || NPP[y]) cout << 0 << '\n' ; else cout << BFS(x, y) << '\n' ; } } /* 9 12 1 9 4 1 2 5 2 3 7 2 4 3 4 3 6 3 6 4 8 7 10 6 7 5 5 8 1 9 5 7 5 4 12 6 8 2 2 4 7 5 1 6 5 3 4 8 5 8 1 5 */

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

plan.cpp: In function 'long long int BFS(long long int, long long int)':
plan.cpp:26:26: warning: control reaches end of non-void function [-Wreturn-type]
   26 |     vector < long long > dd;
      |                          ^~
#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...