This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define INF 200000000000000LL
#define DIMN 100010
using namespace std;
long long d[DIMN] , ds[DIMN] , dt[DIMN];
vector <pair <int,long long> > v[DIMN] , w[DIMN];
priority_queue <pair <long long,int> > h;
struct idk{
int x , y;
long long z;
} mch[2*DIMN];
int n;
void dijkstra (int s , long long d[]){
int i , nod , vecin;
long long cost , c;
for (i = 1 ; i <= n ; i++)
d[i] = INF;
d[s] = 0;
h.push(make_pair( 0 , s ));
while (!h.empty()){
nod = h.top().second;
cost = -h.top().first;
h.pop();
if (d[nod] != cost)
continue;
for (i = 0 ; i < v[nod].size() ; i++){
vecin = v[nod][i].first;
c = v[nod][i].second;
if (d[vecin] > d[nod] + c){
d[vecin] = d[nod] + c;
h.push(make_pair(-d[vecin] , vecin));
}
}
}
}
int main()
{
FILE *fin = stdin;
FILE *fout = stdout;
int i , m , s , t , u , vv , nod , vecin , x , y , z;
long long c , cost;
fscanf (fin,"%d%d%d%d%d%d",&n,&m,&s,&t,&u,&vv);
for (i = 1 ; i <= m ; i++){
fscanf (fin,"%d%d%d",&x,&y,&z);
v[x].push_back(make_pair(y , z));
v[y].push_back(make_pair(x , z));
mch[i] = {x , y , z};
}
/// un dijkstra din s
dijkstra (s , ds);
/// un dijkstra din t
dijkstra (t , dt);
for (i = 1 ; i <= m ; i++){
x = mch[i].x;
y = mch[i].y;
z = mch[i].z;
/// poate muchia x y sa fie pe drum?
if (ds[x] + dt[y] + z == ds[t] || ds[y] + dt[x] + z == ds[t]){
w[x].push_back(make_pair(y , 0));
w[y].push_back(make_pair(x , 0));
/// poate
}
else {
w[x].push_back(make_pair(y , z));
w[y].push_back(make_pair(x , z));
/// nu poate
}
}
/// inca un dijkstra dar pe w intre u si v
for (i = 1 ; i <= n ; i++)
d[i] = INF;
d[u] = 0;
h.push(make_pair( 0 , u ));
while (!h.empty()){
nod = h.top().second;
cost = -h.top().first;
h.pop();
if (d[nod] != cost)
continue;
for (i = 0 ; i < w[nod].size() ; i++){
vecin = w[nod][i].first;
c = w[nod][i].second;
if (d[vecin] > d[nod] + c){
d[vecin] = d[nod] + c;
h.push(make_pair(-d[vecin] , vecin));
}
}
}
fprintf (fout,"%lld",d[vv]);
return 0;
}
Compilation message (stderr)
commuter_pass.cpp: In function 'void dijkstra(int, long long int*)':
commuter_pass.cpp:34:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 0 ; i < v[nod].size() ; i++){
~~^~~~~~~~~~~~~~~
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:106:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 0 ; i < w[nod].size() ; i++){
~~^~~~~~~~~~~~~~~
commuter_pass.cpp:54:12: 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,&vv);
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:57:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
fscanf (fin,"%d%d%d",&x,&y,&z);
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |