传送门

这个题比较水,很容易看出

1、最短路小于d,直接看奇偶性就好了

2,最短路大于d,puts("NIE\n");

主要就是判奇偶性的问题,将每个点拆成奇点和偶点跑bfs就行了

在线需要开short,不然空间会炸,离线就没有这个忧虑

代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
void read(int &x) {
char ch; bool ok;
for(ok=0,ch=getchar(); !isdigit(ch); ch=getchar()) if(ch=='-') ok=1;
for(x=0; isdigit(ch); x=x*10+ch-'0',ch=getchar()); if(ok) x=-x;
}
#define rg register
const int maxn=5e3+1;
int n,m,k,ans,pre[maxn*4],nxt[maxn*4],h[maxn*2],cnt;
short g[maxn][maxn*2];
queue<int>q;
void add(int x,int y)
{
pre[++cnt]=y,nxt[cnt]=h[x],h[x]=cnt;
pre[++cnt]=x,nxt[cnt]=h[y],h[y]=cnt;
}
void bfs(int y)
{
q.push(y);
while(!q.empty())
{
int x=q.front();q.pop();
for(rg int i=h[x];i;i=nxt[i])
if(!g[y][pre[i]])g[y][pre[i]]=g[y][x]+1,q.push(pre[i]);
}
}
int main()
{
read(n),read(m),read(k);
for(rg int i=1,x,y;i<=m;i++)read(x),read(y),add(x,y+n),add(x+n,y);
for(rg int i=1;i<=n;i++)bfs(i);
for(rg int i=1,x,y,z;i<=k;i++)
{
read(x),read(y),read(z);
if(z&1)(g[x][y+n]&&g[x][y+n]<=z)?printf("TAK\n"):printf("NIE\n");
else (g[x][y]&&g[x][y]<=z)?printf("TAK\n"):printf("NIE\n");
}
}

最新文章

  1. 我的第一个WebAPI程序
  2. 升级AutoMapper后遇到的“Missing map”与“Missing type map configuration”问题
  3. lvm[12446]: Another thread is handling an event. Waiting
  4. elasticsearch中如何高效的使用filter
  5. C++之jsoncpp学习
  6. Codeforces Round #384 (Div. 2)B. Chloe and the sequence 数学
  7. State状态设计模式
  8. dtd语法之定义元素
  9. C++三种内存分配方式
  10. 14种网页图片和文字特效的jQuery插件代码
  11. json操作json类型转换
  12. UDP传输包大小(转)
  13. 想不到的:js中加号操作符
  14. 【公众号系列】SAP的新零售
  15. MySQL中的EXPLAIN
  16. robotframework接口之上传图片
  17. GIS 案例教程-蜂窝多边形制作模型
  18. python txt文件常用读写操作
  19. mysql查询数据
  20. P2512 [HAOI2008]糖果传递

热门文章

  1. Qt JSON解析生成笔记
  2. MongoDB 学习一
  3. assign,copy,strong,weak,nonatomic的具体理解
  4. Eclipse快捷键【转载】
  5. hihocoder #1103 : Colorful Lecture Note微软苏州校招笔试 1月10日(字符串处理+栈)
  6. VK Cup 2015 - Round 2 E. Correcting Mistakes —— 字符串
  7. Duplicate files copied in APK META-INF/DEPENDENCIES
  8. python cassandra 创建space table并写入和查询数据
  9. 【应用】SVG饼状图
  10. 基于候选区域的R-CNN系列网络简介