#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define fi first
#define se second
int k,ti[10005][105];
vector<pii> g[10005];
bool vis[10005][105];
void dij(){
priority_queue<pii,vector<pii>,greater<pii> > q;
memset(ti,0x3f,sizeof ti);
q.push({ti[1][0]=0,1});
while(!q.empty()){
int u=q.top().second,tmp=q.top().first; q.pop();
if(vis[u][tmp%k])continue;
vis[u][tmp%k]=true;
for(auto i:g[u]){
//AC
int moo=tmp;
while(moo<i.se)moo+=k;
if(ti[i.fi][(moo+1)%k]>moo+1)ti[i.fi][(moo+1)%k]=moo+1,q.push({moo+1,i.fi});
//WA 85pts
// while(tmp<i.se)tmp+=k;
// if(ti[i.fi][(tmp+1)%k]>tmp+1)ti[i.fi][(tmp+1)%k]=tmp+1,q.push({tmp+1,i.fi});
}
}
}
int main(){
int n,m,u,v,a;
cin>>n>>m>>k;
while(m--)cin>>u>>v>>a,g[u].push_back({v,a});
dij(),cout<<(vis[n][0]?ti[n][0]:-1);
return 0;
}
rt,请问AC和WA的写法在本题中到底有什么区别?