提交记录 12026


用户 题目 状态 得分 用时 内存 语言 代码长度
panyf noip17c. 【NOIP2017】逛公园 Accepted 100 515.312 ms 48540 KB C++11 1.44 KB
提交时间 评测时间
2020-03-08 19:03:20 2020-08-01 02:50:23
#include<cstdio>
#include<cstring>
#include<queue>
#include<utility>
using namespace std;
char ch[29999999],*it=ch;
void in(int&x){
	for(x=0;*it<'0'||*it>'9';++it);
	for(;x=x*10+*it-48,*++it>='0'&&*it<='9';);
}
const int N=100009,M=200009;
int n,m,K,p,d[N],g[N][55];
int ne[M],to[M],len[M],he[N];
int ner[M],tor[M],her[N];
bool f[N],b[N][55],s[N][55],er;
priority_queue<pair<int,int> >Q;
void dfs(const int&x,const int&y){
	if(s[x][y]){
		er=1;
		return;
	}
	if(b[x][y])return;
	s[x][y]=1;
	if(x==1&&y==0)g[x][y]=1;
	register int i,j,k;
	for(j=her[x];j;j=ner[j]){
		if(er)return;
		i=tor[j],k=d[x]+y-len[j]-d[i];
		if(k>=0)dfs(i,k),g[x][y]=(g[x][y]+g[i][k])%p;
	}
	b[x][y]=1,s[x][y]=0;
}
int main(){
	fread(ch,1,29999991,stdin);
	register int T,i,j,k,l,t,a;
	in(T);
	while(T--){
		in(n),in(m),in(K),in(p);
		memset(he,0,sizeof(he)),memset(her,0,sizeof(her));
		memset(f,0,sizeof(f)),er=t=a=0;
		while(m--){
			in(i),in(j),in(k);
			ne[++t]=he[i],to[t]=j,len[t]=k,he[i]=t;
			ner[t]=her[j],tor[t]=i,her[j]=t;
		}
		memset(d,63,sizeof(d)),d[1]=0,Q.push(make_pair(0,1));
		while(!Q.empty()){
			i=Q.top().second,Q.pop();
			if(f[i])continue;
			f[i]=1;
			for(j=he[i];j;j=ne[j]){
				k=to[j];
				if(f[k])continue;
				l=d[i]+len[j];
				if(d[k]>l)d[k]=l,Q.push(make_pair(-l,k));
			}
		}
		memset(s,0,sizeof(s)),memset(g,0,sizeof(g)),memset(b,0,sizeof(b));
		for(i=K;i>=0;--i){
			if(er)break;
			dfs(n,i),a=(a+g[n][i])%p;
		}
		if(er)puts("-1");
		else printf("%d\n",a);
	}
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #17.4 ms32 MB + 784 KBAcceptedScore: 10

Testcase #27.645 ms32 MB + 904 KBAcceptedScore: 10

Testcase #312.029 ms32 MB + 928 KBAcceptedScore: 10

Testcase #412.264 ms32 MB + 924 KBAcceptedScore: 10

Testcase #511.805 ms32 MB + 924 KBAcceptedScore: 10

Testcase #611.483 ms32 MB + 928 KBAcceptedScore: 10

Testcase #747.768 ms47 MB + 412 KBAcceptedScore: 10

Testcase #8515.312 ms44 MB + 856 KBAcceptedScore: 10

Testcase #9498.063 ms44 MB + 600 KBAcceptedScore: 10

Testcase #10512.768 ms44 MB + 508 KBAcceptedScore: 10


Judge Duck Online | 评测鸭在线
Server Time: 2024-12-05 10:24:10 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠