Submission #77172

#TimeUsernameProblemLanguageResultExecution timeMemory
77172VardanyanCommuter Pass (JOI18_commuter_pass)C++14
0 / 100
271 ms263168 KiB
#include <bits/stdc++.h>
using namespace std;
const int N = 200*1000+7;
const long long INF = 1000000000000005;
vector<pair<int,long long> > g[N];
long long dist[N];
long long D[N];
long long ans = INF;
int n,m;
int s,t;
int U,V;
vector<vector<int> > all;
bool col[N];
map<pair<int,int>,bool > mp;
vector<int> now;
void dfs(int v,long long ds = 0){
    now.push_back(v);
    if(v == t){
        all.push_back(now);
        return;
    }
    for(int i = 0;i<g[v].size();i++){
        pair<int,long long> to = g[v][i];
        if(ds+to.second>dist[to.first]) continue;
        if(col[to.first]) continue;
        col[to.first] = 1;
        dfs(to.first,ds+to.second);
        col[to.first] = 0;
    }
}
void go(int v,long long ds = 0){
    D[v] = ds;
    if(v == V){
        ans = min(ans,ds);
        return;
    }
    for(int i = 0;i<g[v].size();i++){
        pair<int,long long> to = g[v][i];
        if(mp[{v,to.first}]) to.second = 0;
        if(ds+to.second>=D[to.first]) continue;
        if(col[to.first]) continue;
        col[to.first] = 1;
        go(to.first,ds+to.second);
        col[to.first] = 0;
    }
}
int main(){
    scanf("%d%d",&n,&m);
    scanf("%d%d",&s,&t);
    scanf("%d%d",&U,&V);
    for(int i = 0;i<m;i++){
        int x,y;
        long long z;
        scanf("%d%d%lld",&x,&y,&z);
        g[x].push_back({y,z});
        g[y].push_back({x,z});
    }
    priority_queue<pair<long long,int> > pq;
    pq.push({0,s});
    for(int i = 0;i<=n;i++) dist[i] = INF;
    dist[s] = 0;
    while(!pq.empty()){
        pair<long long,int> gag = pq.top();
        pq.pop();
        for(int i = 0;i<g[gag.second].size();i++){
            int to = g[gag.second][i].first;
            if(dist[to]>(-gag.first)+g[gag.second][i].second){
                dist[to] = (-gag.first)+g[gag.second][i].second;
                pq.push({-dist[to],to});
            }
        }
    }
    dfs(s);
    if(all.size()>1) assert(0);
    /*
    for(int i = 0;i<all.size();i++){
        memset(col,0,sizeof(col));
        for(int j = 0;j<=n;j++) D[j] = INF;
        mp.clear();
        for(int j = 0;j<all[i].size()-1;j++) mp[{all[i][j],all[i][j+1]}] = mp[{all[i][j+1],all[i][j]}] = 1;
        go(U);
    }
    cout<<ans<<endl;
 */
    /*for(int i = 1;i<=n;i++){
        cout<<i<<" "<<dist[i]<<endl;
    }*/
    return 0;
}

Compilation message (stderr)

commuter_pass.cpp: In function 'void dfs(int, long long int)':
commuter_pass.cpp:22:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0;i<g[v].size();i++){
                   ~^~~~~~~~~~~~
commuter_pass.cpp: In function 'void go(int, long long int)':
commuter_pass.cpp:37:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0;i<g[v].size();i++){
                   ~^~~~~~~~~~~~
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:65:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 0;i<g[gag.second].size();i++){
                       ~^~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:48:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&m);
     ~~~~~^~~~~~~~~~~~~~
commuter_pass.cpp:49:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&s,&t);
     ~~~~~^~~~~~~~~~~~~~
commuter_pass.cpp:50:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&U,&V);
     ~~~~~^~~~~~~~~~~~~~
commuter_pass.cpp:54:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%lld",&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...