Submission #50610582


Source Code Expand

#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
const int maxn = 2e5 + 10;
static char buf[1000000],*p1=buf,*p2=buf;
#define getchar() p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++
inline int read(){int x=0,f=1;char c=getchar();while(c<'0' || c>'9'){if(c=='-') f=-1;c=getchar();}while(c>='0' && c<='9') {x=(x<<3)+(x<<1)+c-48;c=getchar();}return x*f;}
inline void write(long long x){static char buf[20];static int len=-1;if(x<0)putchar('-'),x=-x;do buf[++len]=x%10,x/=10;while(x);while(len>=0)putchar(buf[len--]+48);}
#define put() putchar(' ')
#define endl puts("")
struct node
{
    int nxt,to,w,l,d,k;
}e[maxn];
int head[maxn],tot;
void add_edge(int u,int v,int w,int l,int d,int k)
{
    e[++tot] = {head[u],v,w,l,d,k};
    head[u] = tot;
}
int n,m;
long long ans[maxn];
bool vis[maxn];

int main()
{
    n = read();
    m = read();
    for(int i = 1;i <= m;++i)
    {
        int l,d,k,w,u,v;
        l = read();
        d = read();
        k = read();
        w = read();
        u = read();
        v = read();
        add_edge(v,u,w,l,d,k);
    }
    queue<int> q;
    for(int i = head[n];i;i = e[i].nxt)
    {
        int w = e[i].w,l = e[i].l,d = e[i].d,k = e[i].k;
        ans[e[i].to] = l + 1ll * (k - 1) * d;
        q.push(e[i].to);
        vis[e[i].to] = 1;
    }
    while(!q.empty())
    {
        int u = q.front();
        vis[u] = 0;
        q.pop();
        for(int i = head[u];i;i = e[i].nxt)
        {
            int v = e[i].to;
            if(ans[u] < e[i].w || ans[v] > ans[u] || v == n)
            {
                continue;
            }
            long long t = ans[u] - e[i].w;
            t -= e[i].l;
            t /= e[i].d;
            t = min(t,e[i].k - 1ll);
            if(ans[v] < e[i].l + 1ll * t * e[i].d)
            {
                ans[v] = e[i].l + 1ll *  t * e[i].d;
                q.push(v);
                vis[v] = 1;
            }
        }
    }
    for(int i = 1;i < n;++i)
    {
        if(ans[i] != 0)write(ans[i]),endl;
        else puts("Unreachable");
    }
    return 0;
}

Submission Info

Submission Time
Task E - Last Train
User feather_life
Language C++ 20 (gcc 12.2)
Score 450
Code Size 2237 Byte
Status AC
Exec Time 44 ms
Memory 12544 KiB

Compile Error

Main.cpp: In function ‘int main()’:
Main.cpp:47:13: warning: unused variable ‘w’ [-Wunused-variable]
   47 |         int w = e[i].w,l = e[i].l,d = e[i].d,k = e[i].k;
      |             ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 450 / 450
Status
AC × 3
AC × 33
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3620 KiB
00_sample_01.txt AC 1 ms 3496 KiB
00_sample_02.txt AC 1 ms 3500 KiB
01_random_03.txt AC 44 ms 12500 KiB
01_random_04.txt AC 44 ms 12544 KiB
01_random_05.txt AC 43 ms 12512 KiB
01_random_06.txt AC 44 ms 12488 KiB
01_random_07.txt AC 44 ms 12424 KiB
01_random_08.txt AC 36 ms 11740 KiB
01_random_09.txt AC 36 ms 11796 KiB
01_random_10.txt AC 22 ms 10000 KiB
01_random_11.txt AC 26 ms 8936 KiB
01_random_12.txt AC 37 ms 10840 KiB
01_random_13.txt AC 17 ms 7544 KiB
01_random_14.txt AC 9 ms 6260 KiB
01_random_15.txt AC 6 ms 5912 KiB
01_random_16.txt AC 11 ms 6964 KiB
01_random_17.txt AC 22 ms 9912 KiB
01_random_18.txt AC 22 ms 10196 KiB
01_random_19.txt AC 23 ms 9988 KiB
01_random_20.txt AC 23 ms 11376 KiB
01_random_21.txt AC 22 ms 9932 KiB
01_random_22.txt AC 43 ms 9252 KiB
01_random_23.txt AC 14 ms 8008 KiB
01_random_24.txt AC 13 ms 7436 KiB
01_random_25.txt AC 28 ms 11912 KiB
01_random_26.txt AC 28 ms 11792 KiB
01_random_27.txt AC 28 ms 11728 KiB
01_random_28.txt AC 29 ms 11792 KiB
01_random_29.txt AC 7 ms 4096 KiB
01_random_30.txt AC 3 ms 5168 KiB
01_random_31.txt AC 7 ms 7192 KiB
01_random_32.txt AC 12 ms 9204 KiB