提交记录 12802


用户 题目 状态 得分 用时 内存 语言 代码长度
winlere noip17c. 【NOIP2017】逛公园 Accepted 100 481.775 ms 32632 KB C++11 2.59 KB
提交时间 评测时间
2020-06-03 20:16:15 2020-08-01 02:59:04
//@winlere
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>

using namespace std;  typedef long long ll;
inline int qr(){
      register int ret=0,f=0;
      register char c=getchar();
      while(c<48||c>57)f|=c==45,c=getchar();
      while(c>=48&&c<=57) ret=ret*10+c-48,c=getchar();
      return f?-ret:ret;
}
const int maxn=1e5+5;

template<class M>
struct HEAP{
      M data[maxn*2];
      int cnt;
      inline void down(const int&pos){
	    for(int t=pos,k;(t<<1)<=cnt;t=k){
		  k=t<<1;
		  if(k<cnt&&data[k|1]<data[k]) k|=1;
		  if(data[t]>data[k]) swap(data[t],data[k]);
		  else return;
	    }
      }
      inline void up(const int&pos){
	    for(int t=pos;t>>1;t>>=1)
		  if(data[t]<data[t>>1]) swap(data[t],data[t>>1]);
		  else return;
      }
      inline void push(const M&x){data[++cnt]=x,up(cnt);}
      inline void pop(){swap(data[1],data[cnt--]);down(1);}
      inline M top(){return data[1];}
      inline int size(){return cnt;}
};
HEAP< pair<int,int> > q;

struct E{
      int to,nx,w;
      E(){to=nx=w=0;}
      E(const int&x,const int&y,const int&z){to=x; nx=y; w=z;}
}e[maxn<<2];
int head[maxn],cnt,head0[maxn];
inline void add(const int&fr,const int&to,const int&w,int*h=head){e[++cnt]=E(to,h[fr],w),h[fr]=cnt;}
int d[maxn],n,m,k,mod;
typedef pair<int,int> P;

const int inf=1e9;
inline void dij(){
      for(int t=1;t<=n;++t) d[t]=inf;
      q.push((P){d[n]=0,n});
      while(q.size()){
	    P now=q.top(); q.pop();
	    if(now.first>d[now.second]) continue;
	    for(int t=head[now.second];t;t=e[t].nx)
		  if(d[e[t].to]>d[now.second]+e[t].w)
			q.push((P){d[e[t].to]=d[now.second]+e[t].w,e[t].to});
      }
}


int dp[55][maxn];
bool usd[55][maxn];
bool in[55][maxn];
int dfs(const int&now,const int&k){
      if(in[k][now])return -1;
      if(usd[k][now]) return dp[k][now];
      dp[k][now]=now==n;
      in[k][now]=usd[k][now]=1;
      for(int t=head0[now];t;t=e[t].nx){
	    int g=e[t].w-(d[now]-d[e[t].to]),ret;
	    if(g>k)continue;
	    if(ret=dfs(e[t].to,k-g),-1==ret) return dp[k][now]=-1;
	    dp[k][now]=(dp[k][now]+ret)%mod;
      }
      in[k][now]=0;
      return dp[k][now];
}

int main(){
      int T=qr();
      while(T--){
	    cnt=0;
	    n=qr(); m=qr(); k=qr(); mod=qr();
	    for(register int t=0;t<=n;++t) head[t]=head0[t]=0;
	    for(int i=0;i<=k;++i)
		  for(register int t=0;t<=n;++t)
			dp[i][t]=usd[i][t]=in[i][t]=0;
	    for(int t=1,t1,t2,t3;t<=m;++t)
		  t1=qr(),t2=qr(),t3=qr(),add(t2,t1,t3),add(t1,t2,t3,head0);
	    dij();
	    //for(int t=1;t<=n;++t) printf("%d\n",d[t]);
	    printf("%d\n",dfs(1,k));
      }
      return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #1889.36 us6 MB + 168 KBAcceptedScore: 10

Testcase #21.146 ms6 MB + 168 KBAcceptedScore: 10

Testcase #35.415 ms6 MB + 1000 KBAcceptedScore: 10

Testcase #45.906 ms6 MB + 968 KBAcceptedScore: 10

Testcase #55.329 ms6 MB + 1016 KBAcceptedScore: 10

Testcase #65.008 ms7 MB + 36 KBAcceptedScore: 10

Testcase #747.548 ms6 MB + 260 KBAcceptedScore: 10

Testcase #8463.796 ms29 MB + 568 KBAcceptedScore: 10

Testcase #9469.043 ms27 MB + 776 KBAcceptedScore: 10

Testcase #10481.775 ms31 MB + 888 KBAcceptedScore: 10


Judge Duck Online | 评测鸭在线
Server Time: 2024-03-28 17:36:54 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用