栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

poj 2702 Can a Complicated Pr...

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

poj 2702 Can a Complicated Pr...

#include<iostream>#include<cstring>#include<cstdio>#include<algorithm>#include<cmath>#include<stack>#include<queue>#include<vector>#include<map>#include<ctime>#include<set>using namespace std;const int MAX=20005;const int inf=1<<30;#define ll long long#define PII pair<int,int>#define MP(x,y) make_pair(x,y)int a[505][26],b[505][26],n,m,S,from[505],to[505],c[505];bool vis[505][505];bool bfs(int s1,int s2){    memset(vis,0,sizeof(vis));    vis[s1][s2]=1;    queue<pair<int,int> >que;    que.push(MP(s1,s2));    int u1,u2;    while(!que.empty())    {        PII now=que.front();        que.pop();        int x1=now.first,x2=now.second;        for(int i=0;i<26;i++)        { if(a[x1][i]!=-1) {     u1=a[x1][i];     u2=b[x2][i];     if(u2==-1)         u2=x2;     if(u2==0)         return false;     if(!vis[u1][u2])     {         vis[u1][u2]=1;         que.push(MP(u1,u2));     } }        }    }    return true;}char str[300];int main(){    int i,j,k,T;    scanf("%d",&T);    while(T--)    {        scanf("%d%d%d",&n,&m,&S);        memset(a,-1,sizeof(a));        memset(b,-1,sizeof(b));        int s1=S;        for(int x=0;x<m;x++)        { scanf("%d%s%d",&from[x],str,&to[x]); c[x]=str[0]-'a'; a[from[x]][c[x]]=to[x];        }        scanf("%d%d%d",&n,&m,&S);        for(int x=0;x<m;x++)        { scanf("%d%s%d",&from[x],str,&to[x]); if(to[x]==-1)     to[x]++; c[x]=str[0]-'a'; b[from[x]][c[x]]=to[x];        }        if(bfs(s1,S)) puts("satisfied");        else puts("violated");    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/374296.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号