poj 3997 Stock Chase

poj 3997 Stock Chase,第1张

poj 3997 Stock Chase
#include <iostream>#include <cstdio>#include <cstring>using namespace std;bool graph[250][250];int main(){    int n,t,casecnt=0;    while(scanf("%d%d",&n,&t)!=EOF,!(n==0&&t==0))    {        int res=0;        memset(graph,0,sizeof(graph));        for(int i=1;i<=n;i++) graph[i][i]=true;        for(int i=0;i<t;i++)        { int a,b; scanf("%d%d",&a,&b); if(graph[b][a]) { res++; } else if(!graph[a][b]) {     graph[a][b]=true;     for(int j=1;j<=n;j++)     {         if(graph[j][a])         {  graph[j][b]=true;  for(int k=1;k<=n;k++)  {      if(graph[b][k]) graph[j][k]=true;  }         }     } }        }        casecnt++;        printf("%d. %dn",casecnt,res);    }    return 0;}

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/4914642.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-12
下一篇2022-11-12

发表评论

登录后才能评论

评论列表(0条)

    保存