제출 #1342195

#제출 시각아이디문제언어결과실행 시간메모리
1342195gry3125Currents (EGOI25_currents)C++20
100 / 100
592 ms32116 KiB
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define ll long long int
#define all(v) (v).begin(),(v).end()
using namespace std;

vector<int> adj[200005], adjj[200005];
vector<ll> d(200005), ed(200005), ans(200005);
int main() {
    int n, m; cin >> n >> m;
    while (m--) {
        int a, b; cin >> a >> b;
        adj[a].pb(b); adjj[b].pb(a);
    }
    priority_queue<pair<int,ll>,vector<pair<int,ll>>,greater<pair<int,ll>>> q;
    d[0] = 0; for (int i = 1; i < n; i++) d[i] = 1e18;
    q.push({d[0],0});
    while (!q.empty()) {
        int v = q.top().se; ll cur = q.top().fi; q.pop();
        if (cur != d[v]) continue;
        for (auto x : adj[v]) {
            if (d[x] > d[v] + 1) {
                d[x] = d[v] + 1;
                q.push({d[x],x});
            }
        }
    }
    ed[n-1] = 0; for (int i = 0; i < n-1; i++) ed[i] = 1e18;
    q.push({ed[n-1],n-1});
    while (!q.empty()) {
        int v = q.top().se; ll cur = q.top().fi; q.pop();
        if (cur != ed[v]) continue;
        for (auto u : adjj[v]) {
            if (ed[u] > ed[v] + 1) {
                ed[u] = max(ed[v] + 1, d[u]);
                q.push({ed[u],u});
            }
        }
    }
    for (int i = 0; i < n-1; i++) cout << ed[i] << " ";
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...