Submission #103355

#TimeUsernameProblemLanguageResultExecution timeMemory
103355tincamateiCommuter Pass (JOI18_commuter_pass)C++14
0 / 100
2050 ms18604 KiB
#include <bits/stdc++.h> using namespace std; const int MAX_N = 100000; const long long INF = 1LL << 60; vector<pair<int, int> > graph[1+MAX_N]; long long dist[2][1+MAX_N], dists[1+MAX_N]; long long dp[1+MAX_N][2]; void dijkstra(int n, int src, long long *dist) { priority_queue<pair<long long, int> > pq; for(int i = 1; i <= n; ++i) dist[i] = INF; dist[src] = 0; pq.push(make_pair(0, src)); while(!pq.empty()) { int nod = pq.top().second; long long cost = -pq.top().first; pq.pop(); if(cost == dist[nod]) { for(auto it: graph[nod]) if(cost + it.second < dist[it.first]) { dist[it.first] = cost + it.second; pq.push(make_pair(-cost - it.second, it.first)); } } } } void computeDp(int nod) { dp[nod][0] = dp[nod][1] = INF; for(auto it: graph[nod]) if(dists[nod] - it.second == dists[it.first]) { computeDp(it.first); for(int i = 0; i < 2; ++i) dp[nod][i] = min(dp[nod][i], dp[it.first][i]); } for(int i = 0; i < 2; ++i) dp[nod][i] = min(dp[nod][i], dist[i][nod]); } int main() { #ifdef HOME FILE *fin = fopen("input.in", "r"); FILE *fout = fopen("output.out", "w"); #else FILE *fin = stdin; FILE *fout = stdout; #endif int n, m, s, t, u, v; int a, b, c; fscanf(fin, "%d%d%d%d%d%d", &n, &m, &s, &t, &u, &v); for(int i = 0; i < m; ++i) { fscanf(fin, "%d%d%d", &a, &b, &c); graph[a].push_back(make_pair(b, c)); graph[b].push_back(make_pair(a, c)); } dijkstra(n, u, dist[0]); dijkstra(n, v, dist[1]); dijkstra(n, s, dists); computeDp(t); fprintf(fout, "%lld", dp[t][0] + dp[t][1]); fclose(fin); fclose(fout); return 0; }

Compilation message (stderr)

commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:63:8: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  fscanf(fin, "%d%d%d%d%d%d", &n, &m, &s, &t, &u, &v);
  ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:65:9: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   fscanf(fin, "%d%d%d", &a, &b, &c);
   ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...