답안 #475940

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
475940 2021-09-24T13:37:58 Z s_jaskaran_s Robot (JOI21_ho_t4) C++17
0 / 100
37 ms 4256 KB
#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];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 37 ms 4256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -