Submission #616562


Source Code Expand

#include<bits/stdc++.h>
using namespace std;

#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

#define mygc(c) (c)=getchar_unlocked()
#define mypc(c) putchar_unlocked(c)

#define ll long long
#define ull unsigned ll

void reader(int *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);}
void reader(ll *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);}
void reader(double *x){scanf("%lf",x);}
int reader(char c[]){int i,s=0;for(;;){mygc(i);if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF) break;}c[s++]=i;for(;;){mygc(i);if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF) break;c[s++]=i;}c[s]='\0';return s;}
template <class T, class S> void reader(T *x, S *y){reader(x);reader(y);}
template <class T, class S, class U> void reader(T *x, S *y, U *z){reader(x);reader(y);reader(z);}
template <class T, class S, class U, class V> void reader(T *x, S *y, U *z, V *w){reader(x);reader(y);reader(z);reader(w);}

void writer(int x, char c){int s=0,m=0;char f[10];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);}
void writer(ll x, char c){int s=0,m=0;char f[20];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);}
void writer(double x, char c){printf("%.15f",x);mypc(c);}
void writer(const char c[]){int i;for(i=0;c[i]!='\0';i++)mypc(c[i]);}
void writer(const char x[], char c){int i;for(i=0;x[i]!='\0';i++)mypc(x[i]);mypc(c);}
template<class T> void writerLn(T x){writer(x,'\n');}
template<class T, class S> void writerLn(T x, S y){writer(x,' ');writer(y,'\n');}
template<class T, class S, class U> void writerLn(T x, S y, U z){writer(x,' ');writer(y,' ');writer(z,'\n');}
template<class T> void writerArr(T x[], int n){int i;if(!n){mypc('\n');return;}rep(i,n-1)writer(x[i],' ');writer(x[n-1],'\n');}

char memarr[17000000]; void *mem = memarr;
#define MD 1000000007
#define INF 10000000000000000LL

template <class T>
struct heapEx {
  int *hp, *place, size; T *val;

  void malloc(int N){hp=(int*)std::malloc(N*sizeof(int));place=(int*)std::malloc(N*sizeof(int));val=(T*)std::malloc(N*sizeof(T));}
  void free(){free(hp);free(place);free(val);}
  void* malloc(int N, void *workMemory){hp=(int*)workMemory;workMemory=(void*)(hp+N);place=(int*)workMemory;workMemory=(void*)(place+N);val=(T*)workMemory;workMemory=(void*)(val+N);return workMemory;}
  void init(int N){int i;size=0;rep(i,N)place[i]=-1;}
  void up(int n){int m;while(n){m=(n-1)/2;if(val[hp[m]]<=val[hp[n]])break;swap(hp[m],hp[n]);swap(place[hp[m]],place[hp[n]]);n=m;}}
  void down(int n){int m;for(;;){m=2*n+1;if(m>=size)break;if(m+1<size&&val[hp[m]]>val[hp[m+1]])m++;if(val[hp[m]]>=val[hp[n]])break;swap(hp[m],hp[n]);swap(place[hp[m]],place[hp[n]]);n=m;}}
  void change(int n, T v){T f=val[n];val[n]=v;if(place[n]==-1){place[n] = size;hp[size++] = n;up(place[n]);}else{if(f < v) down(place[n]); else if(f > v) up(place[n]);}}
  int pop(void){int res=hp[0];place[res]=-1;size--;if(size)hp[0]=hp[size],place[hp[0]]=0,down(0);return res;}
};


int N, M, st, ed;
int L[300000];
vector<int> s[300000], w[300000], wws[300000];

ll cost1[300000], cost2[300000];

vector<int> des1[30000], des2[30000], rev_a[30000], rev_i[30000];
vector<ll>  cos1[30000], cos2[30000];

int main(){
  int i, j, k, ind;
  int a, b, c;
  ll nc;
  heapEx<ll> heap;

  reader(&N,&M,&st,&ed);
  rep(i,M){
    reader(L+i);
    rep(j,L[i]){
      reader(&k);
      s[i].push_back(k);
    }
    rep(j,L[i]-1){
      reader(&k);
      w[i].push_back(k);
    }
    wws[i].push_back(0);
    rep(j,L[i]-1) wws[i].push_back(wws[i][j]+w[i][j]);
  }

  rep(i,M){
    rep(j,L[i]-1){
      a = s[i][j];
      b = s[i][j+1];
      c = s[i][L[i]-1];
      des1[a].push_back(b);
      des2[a].push_back(c);
      cos1[a].push_back(wws[i][j+1] - wws[i][j]);
      cos2[a].push_back(wws[i][L[i]-1] - wws[i][j]);

      rev_a[b].push_back(a);
      rev_i[b].push_back(des1[a].size()-1);
    }
    REP(j,1,L[i]){
      a = s[i][j];
      b = s[i][j-1];
      c = s[i][0];
      des1[a].push_back(b);
      des2[a].push_back(c);
      cos1[a].push_back(wws[i][j] - wws[i][j-1]);
      cos2[a].push_back(wws[i][j] - wws[i][0]);

      rev_a[b].push_back(a);
      rev_i[b].push_back(des1[a].size()-1);
    }
  }

  heap.malloc(N);

  heap.init(N);
  rep(i,N) cost2[i] = INF;
  cost2[ed] = 0;
  heap.change(ed,0);
  while(heap.size){
    i = heap.pop();
    rep(j,des1[i].size()){
      k = des1[i][j];
      if(cost2[k] > cost2[i]+cos1[i][j]){
        cost2[k] = cost2[i]+cos1[i][j];
        heap.change(k,cost2[k]);
      }
    }
  }

  heap.init(N);
  rep(i,N) cost1[i] = INF;
  cost1[ed] = 0;
  heap.change(ed,cost1[ed]);
  while(heap.size){
    i = heap.pop();
    rep(j,rev_a[i].size()){
      a = rev_a[i][j];
      ind = rev_i[i][j];

      b = des1[a][ind];
      c = des2[a][ind];
      nc = max(cos1[a][ind]+cost1[b], cos2[a][ind]+cost2[c]);
      if(cost1[a] > nc){
        cost1[a] = nc;
        heap.change(a,cost1[a]);
      }
    }
  }
  
  writerLn(cost1[st]);

  return 0;
}

Submission Info

Submission Time
Task C - メンテナンス明け
User LayCurse
Language C++ (GCC 4.9.2)
Score 100
Code Size 5396 Byte
Status AC
Exec Time 187 ms
Memory 34212 KB

Compile Error

./Main.cpp: In function ‘void reader(double*)’:
./Main.cpp:15:38: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
 void reader(double *x){scanf("%lf",x);}
                                      ^

Judge Result

Set Name Subtask1 Subtask2
Score / Max Score 50 / 50 50 / 50
Status
AC × 52
AC × 6
Set Name Test Cases
Subtask1 small/00_sample00, small/00_sample01, small/00_sample02, small/10_small-0000, small/10_small-0001, small/10_small-0002, small/10_small-0003, small/10_small-0004, small/10_small-0005, small/10_small-0006, small/10_small-0007, small/10_small-0008, small/10_small-0009, small/10_small-0010, small/10_small-0011, small/10_small-0012, small/10_small-0013, small/10_small-0014, small/10_small-0015, small/10_small-0016, small/10_small-0017, small/10_small-0018, small/10_small-0019, small/30_max_small, small/40_simple_0000, small/40_simple_0001, small/40_simple_0002, small/40_simple_0003, small/40_simple_0004, small/40_simple_0005, small/40_simple_0006, small/40_simple_0007, small/40_simple_0008, small/40_simple_0009, small/40_simple_0010, small/40_simple_0011, small/40_simple_0012, small/40_simple_0013, small/40_simple_0014, small/40_simple_0015, small/40_simple_0016, small/40_simple_0017, small/40_simple_0018, small/40_simple_0019, small/90_dijkstra_killer_00, small/90_dijkstra_killer_01, small/91_tayama_killer_00, small/91_tayama_killer_01, small/91_tayama_killer_02, small/91_tayama_killer_03, small/91_tayama_killer_04, small/91_tayama_killer_05
Subtask2 large/20_large-00, large/20_large-01, large/20_large-02, large/20_large-03, large/20_large-04, large/31_max_large
Case Name Status Exec Time Memory
large/20_large-00 AC 178 ms 34076 KB
large/20_large-01 AC 180 ms 34208 KB
large/20_large-02 AC 178 ms 34212 KB
large/20_large-03 AC 176 ms 33952 KB
large/20_large-04 AC 187 ms 34076 KB
large/31_max_large AC 114 ms 31776 KB
small/00_sample00 AC 76 ms 26020 KB
small/00_sample01 AC 76 ms 26016 KB
small/00_sample02 AC 73 ms 26024 KB
small/10_small-0000 AC 71 ms 26148 KB
small/10_small-0001 AC 77 ms 26148 KB
small/10_small-0002 AC 74 ms 26144 KB
small/10_small-0003 AC 82 ms 26144 KB
small/10_small-0004 AC 76 ms 26148 KB
small/10_small-0005 AC 75 ms 26144 KB
small/10_small-0006 AC 74 ms 26132 KB
small/10_small-0007 AC 71 ms 26136 KB
small/10_small-0008 AC 74 ms 26144 KB
small/10_small-0009 AC 75 ms 26152 KB
small/10_small-0010 AC 74 ms 26156 KB
small/10_small-0011 AC 74 ms 26136 KB
small/10_small-0012 AC 69 ms 26144 KB
small/10_small-0013 AC 77 ms 26084 KB
small/10_small-0014 AC 69 ms 26212 KB
small/10_small-0015 AC 75 ms 26164 KB
small/10_small-0016 AC 69 ms 26140 KB
small/10_small-0017 AC 76 ms 26148 KB
small/10_small-0018 AC 75 ms 26144 KB
small/10_small-0019 AC 70 ms 26140 KB
small/30_max_small AC 70 ms 26140 KB
small/40_simple_0000 AC 71 ms 26008 KB
small/40_simple_0001 AC 66 ms 26016 KB
small/40_simple_0002 AC 75 ms 26024 KB
small/40_simple_0003 AC 70 ms 26020 KB
small/40_simple_0004 AC 74 ms 26020 KB
small/40_simple_0005 AC 76 ms 26016 KB
small/40_simple_0006 AC 74 ms 26020 KB
small/40_simple_0007 AC 74 ms 26020 KB
small/40_simple_0008 AC 73 ms 26020 KB
small/40_simple_0009 AC 74 ms 26020 KB
small/40_simple_0010 AC 71 ms 26020 KB
small/40_simple_0011 AC 73 ms 26028 KB
small/40_simple_0012 AC 74 ms 26016 KB
small/40_simple_0013 AC 75 ms 26012 KB
small/40_simple_0014 AC 69 ms 26012 KB
small/40_simple_0015 AC 69 ms 26008 KB
small/40_simple_0016 AC 70 ms 26020 KB
small/40_simple_0017 AC 69 ms 26020 KB
small/40_simple_0018 AC 74 ms 26020 KB
small/40_simple_0019 AC 69 ms 26028 KB
small/90_dijkstra_killer_00 AC 74 ms 26020 KB
small/90_dijkstra_killer_01 AC 69 ms 26020 KB
small/91_tayama_killer_00 AC 70 ms 26008 KB
small/91_tayama_killer_01 AC 69 ms 26088 KB
small/91_tayama_killer_02 AC 76 ms 26016 KB
small/91_tayama_killer_03 AC 73 ms 26024 KB
small/91_tayama_killer_04 AC 73 ms 26016 KB
small/91_tayama_killer_05 AC 74 ms 26024 KB