Cojs 1001. [WZOI2011 S3] Message delivery

Source: Internet
Author: User

1001. [WZOI2011 S3] Message delivery

★ Import File: messagew.in output file: messagew.out Simple comparison
Time limit: 1 s memory limit: MB

Problem 2 Message delivery (MESSAGEW.PAS/C/CPP)

Problem Description

Wzland opened a club (which can do anything), which attracted a lot of people to join. The number of clubs is increasing and the relationship is becoming
more and more complex ...

The club's people came from all over the place, and in order to increase friendship, the club held a party. At the party, another word game, if a knows B, then a receives a message, it will pass the message to B, as well as all a know the person (if a knows b,b not necessarily know a), everyone from 1 to n number.

now given all the "know" relationships, the head of the club, Wzland's king, wants to know a very simple question: if a releases a new message, the message is passed back to A,1≤a≤n after several passes. But the king of Wzland is famous for his poor maths, but fortunately you are at his side, so he will give you this problem to solve.




Input Format

the first line in the input data is two numbers n and M, and there is a space between two numbers that represents the number of people and the number of cognitive relationships.

the next M-line, two numbers a and b for each line, indicates that a recognizes B (1 A, bn,ab).

output Format

a total of n rows in the output file, one character "T" or "F" per line. Line I if it is "T", means I send a new message will be passed back to I; if it is "F", means I send a new message will not be returned to I.

sample input and output

message.in

4 6

1 2

2 3

4 1

3 1

1 3

2 3

Message.out

T

T

T

F




Data Size

for 30% of data, n≤1000,m≤20000;

for 50% of data, n≤10000,m≤100000;

for 100% of data, n≤100000,m≤200000;

The cognitive relationship may be repeated.

time limit

1s

Exercises

Tarjan

AC Code:

#include <cstdio>#include<vector>#include<stack>using namespacestd;#defineN 100010intN,m,sd,pd,id[n],sum[n],low[n],dfn[n];BOOLMark[n];stack<int>S;vector<int>Grap[n];voidTarjan (intv) {Low[v]=dfn[v]=++PD; MARK[V]=1;    S.push (v);  for(intI=0; I<grap[v].size (); i++){        intw=Grap[v][i]; if(!Dfn[w])            {Tarjan (w); LOW[V]=min (low[v],low[w]); }        Else if(Mark[w]) {Low[v]=min (low[v],dfn[w]); }    }    intu; if(low[v]==Dfn[v]) {SD++;  Do{u=S.top ();            S.pop (); Id[u]=SD; SUM[SD]++; Mark[u]=0; } while(u!=v); }}intMain () {Freopen ("messagew.in","R", stdin); Freopen ("Messagew.out","W", stdout); scanf ("%d%d",&n,&m);  for(intI=1, x,y;i<=m;i++) scanf ("%d%d",&x,&y), Grap[x].push_back (y);  for(intI=1; i<=n;i++)if(!Dfn[i]) Tarjan (i);  for(intI=1; i<=n;i++) puts (sum[id[i]]>1?"T":"F"); return 0;}

Cojs 1001. [WZOI2011 S3] Message delivery

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.