제출 #553376

#제출 시각아이디문제언어결과실행 시간메모리
553376Danilo21Commuter Pass (JOI18_commuter_pass)C++17
0 / 100
425 ms37744 KiB
#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define en '\n'
#define sp ' '
#define tb '\t'
#define ri(n) int n; cin >> n
#define rl(n) ll n; cin >> n
#define rs(s) string s; cin >> s
#define rc(c) char c; cin >> c
#define rv(v) for (auto &x : v) cin >> x
#define pven(v) for (auto x : v) cout << x << en
#define pv(v) for (auto x : v) cout << x << sp; cout << en
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define yes cout << "YES" << en
#define no cout << "NO" << en
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define ssort(a, b) if (a < b) swap(a, b)
#define bitcnt(a) __builtin_popcountll(a)
#define bithigh(a) 63-__builtin_clzll(a)
#define lg bithigh
ll highpow(ll a) { return 1LL << (ll)lg(a); }

using namespace std;

const ll LINF = 4e18;
const int mxN = 2e5+10, INF = 2e9, mod = (1 ? 1e9+7 : 998244353);
ll n, m, S, T, U, V, dp[mxN], dist[2][mxN], indeg[mxN];
vector<array<ll, 2> > g[mxN];
vector<int> b[mxN], dag[mxN], topo;

void Dijkstra(int S, ll* dist = nullptr){

    priority_queue<array<ll, 2>,
            vector<array<ll, 2> >,
            greater<array<ll, 2> > > pq;
    bool vis[n]; memset(vis, 0, sizeof(vis));
    if (!dist) dist = new ll[n];
    for (int i = 0; i < n; i++){ dist[i] = LINF; b[i].clear(); }
    dist[S] = 0;
    pq.push({S, 0});
    while (pq.size()){
        auto [s, d] = pq.top(); pq.pop();
        if (vis[s] || d > dist[s]) continue;
        vis[s] = 1;
        for (auto [u, w] : g[s]){
            if (d + w <= dist[u]){
                dist[u] = d + w;
                pq.push({u, d+w});
                if (d + w < dist[u]) b[u].clear();
                b[u].pb(s);
            }
        }
    }
}

void dfs(int s){

    indeg[s] = 0;
    for (int u : b[s]){
        dag[u].pb(s);
        indeg[s]++;
        if (!~indeg[u]) dfs(u);
    }
}

ll DP(){

    for (int s = 0; s < n; s++) dp[s] = LINF;
    ll ans = LINF;
    for (int s : topo){
        dp[s] = dist[0][s];
        for (int u : dag[s]) smin(dp[s], dp[u]);
        smin(ans, dp[s] + dist[1][s]);
    }
    return ans;
}

void Solve(){

    cin >> n >> m >> S >> T >> U >> V;
    S--; T--; U--; V--;
    for (int i = 0; i < m; i++){
        ri(u); ri(v); rl(w);
        u--; v--;
        g[u].pb({v, w});
        g[v].pb({u, w});
    }
    Dijkstra(U, dist[0]);
    Dijkstra(V, dist[1]);
    Dijkstra(S);
    memset(indeg, -1, sizeof(indeg));
    dfs(T);
    queue<int> q;
    for (int s = 0; s < n; s++)
        if (!indeg[s])
            q.push(s);
    while (q.size()){
        int s = q.front(); q.pop();
        topo.pb(s);
        for (int u : dag[s]){
            indeg[u]--;
            if (!indeg[u]) q.push(u);
        }
    }
    reverse(all(topo));
    ll ans = dist[0][V];
    smin(ans, DP());
    swap(dist[0], dist[1]);
    smin(ans, DP());
    cout << ans << en;
}

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0); cerr.tie(0);
    cout << setprecision(12) << fixed;
    cerr << setprecision(12) << fixed;
    cerr << "Started!" << endl;

    int t = 1;
    //cin >> t;
    while (t--)
        Solve();

    return 0;
}

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

commuter_pass.cpp: In function 'long long int highpow(long long int)':
commuter_pass.cpp:26:22: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   26 | #define bithigh(a) 63-__builtin_clzll(a)
      |                      ^
commuter_pass.cpp:27:12: note: in expansion of macro 'bithigh'
   27 | #define lg bithigh
      |            ^~~~~~~
commuter_pass.cpp:28:38: note: in expansion of macro 'lg'
   28 | ll highpow(ll a) { return 1LL << (ll)lg(a); }
      |                                      ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...