Submission #41883

# Submission time Handle Problem Language Result Execution time Memory
41883 2018-02-22T04:58:10 Z minhtung0404 Snake Escaping (JOI18_snake_escaping) C++14
0 / 100
6 ms 5112 KB
//https://oj.uz/problem/view/JOI18_commuter_pass

#include<bits/stdc++.h>
const int N = 1e5 + 5;
const long long inf = 1e18 + 7;
using namespace std;

typedef pair <int, long long> ii;
vector <ii> adj[N];
vector <long long> dS, dU, dV;

int n, m, U, V, S, T;
long long MinU[N], MinV[N], ans;
bool visitT[N], visit[N];

void dijkstra(int S, vector <long long>& d){
    d.assign(n+1, inf); d[S] = 0;
    priority_queue <ii, vector <ii>, greater <ii>> mq; mq.push({d[S], S});
    while (mq.size()){
        ii z = mq.top(); mq.pop();
        int u = z.second; long long val = z.first;
        if (val != d[u]) continue;
        for (int i = 0; i < adj[u].size(); i++){
            int v = adj[u][i].first; long long cost = adj[u][i].second;
            if (d[v] > d[u] + cost){
                d[v] = d[u] + cost;
                mq.push({d[v], v});
            }
        }
    }
}

void dfs(int u){
    if (visit[u]) return;
    visit[u] = true;
    MinU[u] = MinV[u] = inf;
    if (u == T) visitT[u] = true;
    for (int i = 0; i < adj[u].size(); i++){
        int v = adj[u][i].second; long long cost = adj[u][i].first;
        if (dS[v] != dS[u] + cost) continue;
        dfs(v);
        if (visitT[v] == true){
            visitT[u] = true;
            MinU[u] = min(MinU[u], MinU[v]);
            MinV[u] = min(MinV[u], MinV[v]);
        }
    }
    if (visitT[u] == true){
        MinU[u] = min(MinU[u], dU[u]);
        MinV[u] = min(MinV[u], dV[u]);
        ans = min(ans, MinU[u] + dV[u]);
        ans = min(ans, MinV[u] + dU[u]);
    }
}

int main(){
    scanf("%d %d %d %d %d %d", &n, &m, &S, &T, &U, &V);
    for (int i = 1; i <= m; i++){
        int u, v; long long c;
        scanf("%d %d %lld", &u, &v, &c);
        adj[u].push_back({c, v});
        adj[v].push_back({c, v});
    }
    dijkstra(S, dS); dijkstra(U, dU); dijkstra(V, dV);
    ans = dU[V]; dfs(S);
    printf("%lld", ans);
}

Compilation message

snake_escaping.cpp: In function 'void dijkstra(int, std::vector<long long int>&)':
snake_escaping.cpp:23:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 0; i < adj[u].size(); i++){
                           ^
snake_escaping.cpp: In function 'void dfs(int)':
snake_escaping.cpp:38:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < adj[u].size(); i++){
                       ^
snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:57:55: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d %d %d %d", &n, &m, &S, &T, &U, &V);
                                                       ^
snake_escaping.cpp:60:40: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %lld", &u, &v, &c);
                                        ^
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 5112 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 5112 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 5112 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 5112 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 5112 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -