이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin>>n>>m;
    vector<pair<int,pair<int,int>>> v[n+1];
    for(int i=0;i<m;i++){
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        v[a].push_back({b,{c,d}});
    }
    vector<ll> d(n+1,1000000000000000000);
    d[1]=0;
    set<pair<ll,ll>> s;
    s.insert({0,1});
    vector<int> b(n+1);
    while(s.size()){
        int p=s.begin()->second;
        b[p]=1;
        s.erase(s.begin());
        map<int,int> r;
        for(auto u:v[p]){
            r[u.second.first]++;
        }    
        for(auto u:v[p]){
            if(b[u.first]==0){
                if(s.count({d[u.first],u.first})){
                    s.erase({d[u.first],u.first});
                }
                if(r[u.second.first]==1){
                    d[u.first]=min(d[u.first],d[p]);
                }
                else{
                    d[u.first]=min(d[u.first],d[p]+u.second.second);
                }
                s.insert({d[u.first],u.first});
            }
        }
    }
    if(d[n]==1000000000000000000){
        cout<<-1;
        return 0;
    }
    cout<<d[n];
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |