제출 #1361629

#제출 시각아이디문제언어결과실행 시간메모리
1361629mayacCurrents (EGOI25_currents)C++20
0 / 100
81 ms25292 KiB
#include <bits/stdc++.h>
using namespace std;

int main(){
    int n,m,a,b;
    cin>>n>>m;
    vector<vector<int>> g(n),g2(n);
    for(int i=0;i<m;i++){
        cin>>a>>b;
        g[a].push_back(b);
        g2[b].push_back(a);
    }
    vector<int> d0(n,n),dn(n,2*n);
    d0[0]=0;
    priority_queue<pair<int,int>> q;
    q.push({0,0});
    while(!q.empty()){
        a=q.top().second;q.pop();
        for(int u:g[a]){
            if(d0[u]>d0[a]+1){
                d0[u]=d0[a]+1;
                q.push({d0[u],u});
            }
        }
    }
    for(int u:g2[n-1]){
        dn[u]=d0[u];
        q.push({dn[u],u});
    }
    while(!q.empty()){
        a=q.top().second;q.pop();
        for(int u:g2[a]){
            if(dn[u]>dn[a]+1){
                dn[u]=dn[a]+1;
                q.push({dn[u],u});
            }
        }
    }
    for(int i=0;i<n-1;i++){
        cout<<dn[i]<<" ";
    }
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…