제출 #79689

#제출 시각아이디문제언어결과실행 시간메모리
79689VardanyanCities (BOI16_cities)C++14
0 / 100
501 ms99024 KiB
#include <iostream> #include <vector> #include <queue> #include <algorithm> #include <cmath> #include <map> using namespace std; const long long INF = 1000000000000005; const int N = 1000 * 100 + 7; map<int,long long> dist[N]; long long dp[33][N]; bool colour[33][N]; int A[N]; vector<pair<int, long long> > g[N]; int n, k, m; void diji(int v){ /*if (v == 3){ cout << 0 << endl; }*/ for (int i = 1; i <= n; i++) dist[v][i] = INF; dist[v][v] = 0; priority_queue<pair<long long, int> > pq; pq.push({ 0, v }); while (!pq.empty()){ pair<long long, int> gag = pq.top(); pq.pop(); if (colour[v][gag.second]) continue; colour[v][gag.second] = 1; for (int i = 0; i < g[gag.second].size(); i++){ int to = g[gag.second][i].first; long long d = g[gag.second][i].second; if (d + (-gag.first) < dist[v][to]){ dist[v][to] = d + (-gag.first); pq.push({ -dist[v][to], to }); } } } //for (int i = 1; i <= n; i++) cout << dist[v][i] << " "; //cout << endl; } bool check(int a, int b){ for (int i = 0; i < k; i++){ if ((b >> i) & 1 && !((a >> i) & 1)) return false; } return true; } int rev(int a, int b){ int ans = 0; for (int i = 0; i < k; i++){ if (!((b >> i) & 1) && ((a >> i) & 1)) ans += (1 << i); } return ans; } int main(){ // int c = 1 & 1; // cout << c << endl; cin >> n >> k >> m; for (int i = 1; i <= k; i++) cin >> A[i]; while (m--){ int x, y; long long z; cin >> x >> y >> z; g[x].push_back({ y, z }); g[y].push_back({ x, z }); } for (int i = 0; i <= (1 << k); i++) for (int j = 0; j <= n; j++) dp[i][j] = INF; for (int i = 1; i <= k; i++){ diji(A[i]); for (int j = 1; j <= n; j++){ // cout << dist[A[i]][j] << " "; dp[(1 << (i-1))][j] = dist[A[i]][j]; } // cout << endl; } long long ans = INF; for (int i = 0; i < (1 << k); i++){ for (int j = 0; j < (1 << k); j++){ if (!check(i, j)) continue; //int jj = rev(i,j); int jj = i - j; for (int q = 1; q <= n; q++){ if (dp[j][q]+dp[jj][q]<dp[i][q]) dp[i][q] = dp[j][q] + dp[jj][q]; // cout << dp[i][q] << endl; if (i == ((1 << k) - 1)) ans = min(ans, dp[i][q]); } } } cout << ans << endl; return 0; }

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

cities.cpp: In function 'void diji(int)':
cities.cpp:29:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < g[gag.second].size(); i++){
                   ~~^~~~~~~~~~~~~~~~~~~~~~
#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...