首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
您找到你想要的搜索结果了吗?
是的
没有找到

OJ算法题

#include <stdio.h> #include <string.h> #define MAX 1000 struct Node{     int v,net; }; struct Node node[MAX]; int main(){     int n,e,t,i,x,y,z,head[MAX],que[MAX],map[MAX/2][MAX/2],qh,qt;     while(scanf("%d %d",&n,&e)!=EOF){         memset(head,-1,sizeof(head));         for(i = 0;i < e;i++){             scanf("%d %d",&x,&y);             node[i].v = y;             node[i].net = head[x];             head[x] = i;         }         scanf("%d",&t);         while(t--){             z = 0;             memset(map,0,sizeof(map));             qh = qt = 1;             scanf("%d %d",&x,&y);             if(x == y){                 printf("yes\n");                 continue;             }             que[qt++] = x;             while(qh < qt){                 for(i = head[que[qh]];i != -1;i = node[i].net){                     if(map[que[qh]][node[i].v] == 0){                         map[que[qh]][node[i].v] = 1;                         que[qt++] = node[i].v;                     }                     if(node[i].v == y){                         z = 1;                         break;                     }                 }                 if(z == 1) break;                 qh++;             }             if(z == 1) printf("yes\n");             else printf("no\n");         }         printf("\n");     }     return 0; }

03
领券