제출 #223789

#제출 시각아이디문제언어결과실행 시간메모리
223789Ruxandra985Commuter Pass (JOI18_commuter_pass)C++14
0 / 100
139 ms18412 KiB
#include <bits/stdc++.h>
#define INF 2000000000
#define DIMN 100010
using namespace std;

int d[DIMN] , ds[DIMN] , dt[DIMN];
vector <pair <int,int> > v[DIMN] , w[DIMN];
priority_queue <pair <int,int> > h;
struct idk{
    int x , y , z;
} mch[2*DIMN];

int n;

void dijkstra (int s , int d[]){
    int i , nod , cost , c , vecin;

    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 , c , cost , x , y , z;
    fscanf (fin,"%d%d%d%d%d%d",&n,&m,&s,&t,&u,&vv);

    for (i = 1 ; i <= n ; 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,"%d",d[vv]);

    return 0;
}

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

commuter_pass.cpp: In function 'void dijkstra(int, int*)':
commuter_pass.cpp:31: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:101:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (i = 0 ; i < w[nod].size() ; i++){
                      ~~^~~~~~~~~~~~~~~
commuter_pass.cpp:49: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:52: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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...