Submission #338155

#TimeUsernameProblemLanguageResultExecution timeMemory
338155KazamaHoangCities (BOI16_cities)C++14
14 / 100
287 ms26212 KiB
/* -> Written by <- ----------- K_A_Z_A_M_A ___________ _ | | (^_^) | | /( | )\ | |____|_|____| H O A N G */ #include <bits/stdc++.h> #define Task "" #define F first #define S second #define pb push_back #define bit(x, i) ((x >> (i)) & 1) #define inf 1e9 + 7 #define INF 1e18 + 7 #define ll long long #define pii pair <int, int> #define debug(x) cerr << #x << " is " << x << "\n"; using namespace std; const int MOD = 1e9 + 7; const int maxn = 1e5 + 5; int n, k, m; vector <pair<int, int>> ke[maxn]; int b[maxn]; ll d[4][maxn]; void ijk(int u, ll dis[]){ priority_queue <pair<ll, int>> pq; fill(dis + 1, dis + 1 + n, INF); dis[u] = 0; pq.push({0, u}); while (!pq.empty()){ int u = pq.top().S; ll l = - pq.top().F; pq.pop(); if (l > dis[u]) continue; for (auto p : ke[u]){ int v = p.F; int w = p.S; if (dis[v] > dis[u] + w){ dis[v] = dis[u] + w; pq.push({-dis[v], v}); } } } } void Solve(){ cin >> n >> k >> m; for (int i = 1; i <= k; ++ i){ cin >> b[i]; } for (int i = 1; i <= m; ++ i){ int u, v, w; cin >> u >> v >> w; ke[u].pb({v, w}); ke[v].pb({u, w}); } for (int i = 1; i <= k; ++ i){ ijk(b[i], d[i]); } ll res = INF; for (int i = 1; i <= n; ++ i){ ll cur = 0; for (int j = 1; j <= k; ++ j){ cur += d[j][i]; } res = min(res, cur); } cout << res; } int main(){ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); if(fopen(Task".inp", "r")){ freopen(Task".inp","r",stdin); freopen(Task".out","w",stdout); } int test_case = 1; // cin >> test_case; while (test_case --){ Solve(); } return 0; }

Compilation message (stderr)

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