Submission #72540684


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=2e5+5;
const ll INF=1e18;

int n,m,L,S,T;
vector<pair<int,int>> g[N];
vector<pair<ll,ll>> intervals[N][11]; 
vector<pair<ll,ll>> merge_intervals(vector<pair<ll,ll>>& intervals_vec){
    if(intervals_vec.empty())return {};
    sort(intervals_vec.begin(),intervals_vec.end());
    vector<pair<ll,ll>> res;
    ll l=intervals_vec[0].first,r=intervals_vec[0].second;
    for(int i=1;i<intervals_vec.size();i++){
        if(intervals_vec[i].first<=r+1){
            r=max(r,intervals_vec[i].second);
        }else{
            res.push_back({l,r});
            l=intervals_vec[i].first;
            r=intervals_vec[i].second;
        }
    }
    res.push_back({l,r});
    return res;
}
bool check_intersection(vector<pair<ll,ll>>& intervals_vec,ll S,ll T){
    for(auto &[l,r]:intervals_vec){
        if(!(r<S||l>T))return true;
    }
    return false;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>m>>L>>S>>T;
    
    for(int i=1;i<=m;i++){
        int u,v,c;
        cin>>u>>v>>c;
        g[u].push_back({v,c});
    }
    
    intervals[1][0].push_back({0,0});
    
    for(int step=0;step<L;step++){
        for(int u=1;u<=n;u++){
            if(!intervals[u][step].empty()){
                intervals[u][step]=merge_intervals(intervals[u][step]);
            }
        }
        for(int u=1;u<=n;u++){
            if(intervals[u][step].empty())continue;
            
            for(auto &[v,c]:g[u]){
                for(auto &[l,r]:intervals[u][step]){
                    ll new_l=l+c;
                    ll new_r=min((ll)T,r+c);
                    if(new_l<=new_r){
                        intervals[v][step+1].push_back({new_l,new_r});
                    }
                }
            }
        }
    }
    for(int v=1;v<=n;v++){
        if(!intervals[v][L].empty()){
            intervals[v][L]=merge_intervals(intervals[v][L]);
        }
    }
    
    vector<int> ans;
    for(int v=1;v<=n;v++){
        if(check_intersection(intervals[v][L],S,T)){
            ans.push_back(v);
        }
    }
    
    sort(ans.begin(),ans.end());
    for(int i=0;i<ans.size();i++){
        if(i)cout<<" ";
        cout<<ans[i];
    }
    cout<<"\n";
    return 0;
}

Submission Info

Submission Time
Task D - Paid Walk
User kac17
Language C++23 (GCC 15.2.0)
Score 400
Code Size 2357 Byte
Status AC
Exec Time 162 ms
Memory 94644 KiB

Compile Error

./Main.cpp: In function 'std::vector<std::pair<long long int, long long int> > merge_intervals(std::vector<std::pair<long long int, long long int> >&)':
./Main.cpp:15:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     for(int i=1;i<intervals_vec.size();i++){
      |                 ~^~~~~~~~~~~~~~~~~~~~~
./Main.cpp: In function 'int main()':
./Main.cpp:81:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |     for(int i=0;i<ans.size();i++){
      |                 ~^~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 57
Set Name Test Cases
Sample example_00.txt, example_01.txt, example_02.txt
All example_00.txt, example_01.txt, example_02.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, hand_11.txt, hand_12.txt, hand_13.txt, hand_14.txt, hand_15.txt, hand_16.txt, hand_17.txt, hand_18.txt, hand_19.txt, hand_20.txt, hand_21.txt, hand_22.txt, hand_23.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt
Case Name Status Exec Time Memory
example_00.txt AC 9 ms 3596 KiB
example_01.txt AC 9 ms 3520 KiB
example_02.txt AC 9 ms 3488 KiB
hand_00.txt AC 96 ms 68448 KiB
hand_01.txt AC 130 ms 78380 KiB
hand_02.txt AC 103 ms 71480 KiB
hand_03.txt AC 112 ms 73032 KiB
hand_04.txt AC 100 ms 69992 KiB
hand_05.txt AC 42 ms 14500 KiB
hand_06.txt AC 9 ms 3640 KiB
hand_07.txt AC 9 ms 3604 KiB
hand_08.txt AC 46 ms 11128 KiB
hand_09.txt AC 46 ms 11092 KiB
hand_10.txt AC 13 ms 3576 KiB
hand_11.txt AC 10 ms 3448 KiB
hand_12.txt AC 43 ms 14588 KiB
hand_13.txt AC 43 ms 14648 KiB
hand_14.txt AC 38 ms 14604 KiB
hand_15.txt AC 83 ms 66500 KiB
hand_16.txt AC 88 ms 66484 KiB
hand_17.txt AC 47 ms 11128 KiB
hand_18.txt AC 49 ms 15928 KiB
hand_19.txt AC 48 ms 12664 KiB
hand_20.txt AC 46 ms 11040 KiB
hand_21.txt AC 49 ms 15832 KiB
hand_22.txt AC 130 ms 77524 KiB
hand_23.txt AC 143 ms 78528 KiB
random_00.txt AC 48 ms 12624 KiB
random_01.txt AC 49 ms 12884 KiB
random_02.txt AC 47 ms 12628 KiB
random_03.txt AC 47 ms 12440 KiB
random_04.txt AC 48 ms 12576 KiB
random_05.txt AC 47 ms 13176 KiB
random_06.txt AC 48 ms 15388 KiB
random_07.txt AC 82 ms 64056 KiB
random_08.txt AC 57 ms 26720 KiB
random_09.txt AC 46 ms 12088 KiB
random_10.txt AC 48 ms 12088 KiB
random_11.txt AC 78 ms 61624 KiB
random_12.txt AC 55 ms 24084 KiB
random_13.txt AC 141 ms 85984 KiB
random_14.txt AC 94 ms 67160 KiB
random_15.txt AC 147 ms 86264 KiB
random_16.txt AC 46 ms 10944 KiB
random_17.txt AC 162 ms 94644 KiB
random_18.txt AC 46 ms 11216 KiB
random_19.txt AC 88 ms 35560 KiB
random_20.txt AC 48 ms 12948 KiB
random_21.txt AC 45 ms 11284 KiB
random_22.txt AC 46 ms 11132 KiB
random_23.txt AC 93 ms 43740 KiB
random_24.txt AC 45 ms 12600 KiB
random_25.txt AC 47 ms 12948 KiB
random_26.txt AC 47 ms 12564 KiB
random_27.txt AC 47 ms 12632 KiB
random_28.txt AC 49 ms 12448 KiB
random_29.txt AC 48 ms 12756 KiB