Rqnoj 272 Messenger _rqnoj

Source: Internet
Author: User
Topic description

The group of students from various schools, in order to increase friendship, the party has a word game, if a know B, then a received a message, it will pass this message to B, and all the people who know.
If a knows b,b not necessarily know a.
All the people from 1 to n numbers, give all "understanding" relationship, ask if I release a new message, then will pass a number of messages, this message back to I,1<=i<=n.
Input format

The first line in the input is two numbers n (n<1000) and M (m<10000), and a space between two numbers indicates the number of people and the number of cognitive relationships.
The next m line, two numbers a and b per line, represents a knowing B. 1<=a, B<=n. The cognitive relationship may be repeated, but a line of two numbers will not be the same.
Output format

A total of n rows in the output, one character T or F per line. Line I if it is T, I send a new message back to I; if it is F, I send a new message that does not pass back to I. Sample Input 4 6
1 2
2 3
4 1
3 1
1 3
2 3
Sample output

T
T
T
F


It's kind of like a ring-awarding problem.

But the data is small.

Direct critical table + DFS starting at each point

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int len=1111;
const int lim=11111;
int First[lim],next[lim];

int m,n;
struct Self{int x,y;} S[lim];

BOOL Flag[len];

BOOL Dfs (int i,int root)
{
    int A;
    BOOL P=false;
    Flag[i]=1;
    for (int e=first[i];e!=-1;e=next[e])
    {
        if (s[e].y==root) return true;
        if (!flag[s[e].y])
        {
            P=dfs (s[e].y,root);
            if (p) return p;
        }
    }
    return p;
}
    
int a,b;
int main ()
{
    memset (first,-1,sizeof (a));
    memset (Next,-1,sizeof (next));
    scanf ("%d%d", &m,&n);
    for (a=1;a<=n;a++)
    {
        scanf ("%d%d", &s[a].x,&s[a].y);
        Next[a]=first[s[a].x];
        first[s[a].x]=a;
    }
    
    for (a=1;a<=m;a++)
    {
        memset (flag,0,sizeof (flag));
        if (Dfs (a,a)) cout<< "T" << ' \ n ';
        else cout<< ' F ' << ' \ n ';
    }
    return 0;
}


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.