(01 Dyeing award odd Ring) HDU 3478

Source: Internet
Author: User

Catch

Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 1296 Accepted Submission (s): 632


Problem Descriptiona thief is running away!
We can consider the city where he locates as a undirected graph in which nodes stand for crosses and edges stand for stre Ets. The crosses is labeled from 0 to n–1.
The tricky thief starts he escaping from cross S. Each moment he moves to a adjacent cross. More exactly, assume he was at cross U at the moment T. He may appear at Cross v at moment T + 1 if and only if there are a street between cross U and Cross v. Notice that he may Not stay at the same cross in the consecutive moment.
The cops want to know if there's some moment at which it's possible for the thief of appear at the the city.

Inputthe input contains multiple test cases:
The first line of the input there's an integer T which is the number of test cases. Then the description of T test cases would be given.
For all test case, the first line contains three integers n (≤100), M (≤500), and S. N is the number of crosses. M is the number of streets and S are the index of the cross where the thief starts his escaping.
For the next M lines, there'll be 2 integers u and V in each line (0≤u, v < N). It means there ' s an undirected street between cross U and Cross v.

Outputfor each test case, output one line to tell if there ' s a moment that it's possible for the thief to appear at any CR Oss. Look at the sample output for output format.

Sample Input23 3 00 10 21 22 1 00 1

Sample outputcase 1:yescase 2:no HintFor the first case, just look at the table below. (YES means the thief may appear at the cross at that moment) For the second-input, at any moment, there's at least one cross, the thief can ' t reach.

Source2010 acm-icpc multi-university Training Contest (5)--host by Bjtu
#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <cmath > #include <algorithm> #include <cstdlib> #include <vector> #include <queue>using namespace    std;vector<int> map[100001];int vis[100010];int n,m,s;bool flag=false;void bfs () {queue<int> q;    Q.push (s);    vis[s]=0;    int p;        while (!q.empty ()) {P=q.front ();        Q.pop ();                    for (int i=0;i<map[p].size (); i++) {if (vis[map[p][i]]==-1) {if (vis[p]==1)                vis[map[p][i]]=0;                else vis[map[p][i]]=1;            Q.push (Map[p][i]);            } else {if (vis[map[p][i]]==vis[p]) flag=true;    }}}int Main () {int t,cas;    scanf ("%d", &t);        for (cas=1;cas<=t;cas++) {scanf ("%d%d%d", &n,&m,&s);        memset (vis,-1,sizeof (VIS)); FlAg=false;        for (int i=0;i<n;i++) map[i].clear ();            for (int i=0;i<m;i++) {int A, B;            scanf ("%d%d", &a,&b);            Map[a].push_back (b);        Map[b].push_back (a);        } BFS ();        printf ("Case%d:", CAs);        if (flag) printf ("yes\n");    else printf ("no\n"); } return 0;}

  

(01 Dyeing award odd Ring) HDU 3478

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.