记录编号 |
606598 |
评测结果 |
WWWMMMEEEE |
题目名称 |
3946.信使 |
最终得分 |
0 |
用户昵称 |
xxz |
是否通过 |
未通过 |
代码语言 |
C++ |
运行时间 |
2.559 s |
提交时间 |
2025-10-01 12:15:12 |
内存使用 |
149.10 MiB |
显示代码纯文本
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,mod,q,u,v,d,x,y,ans;
struct node{
int x,step;
}c;
vector<int>g[555];
void bfs(){
queue<node>q;
q.push({u,0});
while(!q.empty()){
c=q.front();q.pop();
if(c.step==d){
if(c.x==v){
ans++;
ans%=mod;
}
continue;
}
x=c.x;
for(int i=0;i<g[x].size();i++){
y=g[x][i];
q.push({y,c.step+1});
}
}
return;
}
signed main(){
freopen("messenger.in","r",stdin);freopen("messenger.out","w",stdout);
scanf("%lld%lld%lld",&n,&m,&mod);
for(int i=i;i<=m;i++){
scanf("%lld%lld",&x,&y);
g[x].push_back(y);
}
scanf("%lld",&q);
while(q--){
ans=0;
scanf("%lld%lld%lld",&u,&v,&d);
bfs();
printf("%lld\n",ans%mod);
}
return 0;
}