Kamishirasawa tone on the indent point

Source: Internet
Author: User

Upper Kamishirasawa Tone
Title Description

In Gensokyo, the Kamishirasawa sound is a well-known teacher with a profound knowledge. Spring snow changes cause many roads in the world to be blocked by heavy snow, so that some students can not successfully reach the village where the Hui sound. So the comet decided to change to a village that could gather the largest number of people as a new teaching location. The earth is made up of N villages (numbered 1). N) and M Road, the road is divided into two kinds of one-way, one for two-way passage, respectively, with 1 and second mark. If there is a pathway from village A to village B, then we think we can reach village B from village A, which is recorded as (A, b). When (A, b) and (b,a) are satisfied at the same time, we think that A, B is absolutely connected, recorded as <A,B>. An absolute connected area is a collection of villages in which any two villages, X, Y, meet <X,Y>. Now your task is to find the largest absolute connected area and output The villages of this absolutely connected area sequentially. If there are two largest, the output dictionary order is minimal, such as the existence of 1,3,4 and 2,5,6 the largest connected regions, the output is 1,3,4.

Input/output format

Input format:

Line 1th: two positive integers n,m

2nd.. M+1 lines: three positive integers per line a,b,t, T = 1 indicates a one-way road from village A to B, T = 2 means that there is a two way road between Village A and a. Ensure that each road appears only once.

Output format:

Line 1th: 1 integers representing the maximum number of villages included in the absolute connected area.

Line 2nd: A number of integers, sequentially outputting the largest absolute connected area that contains the village number.

Indent a naked question.

I finally came to a few times the cycle of ghost animals, I feel that in order to solve the dictionary order problem there will be a better way, but already feel good.

Code:

#include <iostream> #include <cstdio> #include <cstring>using namespace std;const int wx=100017;    inline int read () {int Sum=0,f=1;char ch=getchar (); while (ch< ' 0 ' | |    Ch> ' 9 ') {if (ch== '-') F=-1;ch=getchar ();}    while (ch>= ' 0 ' &&ch<= ' 9 ') {sum= (sum<<1) + (sum<<3) +ch-' 0 '; Ch=getchar ();} return sum*f;} int n,m,num,ans,tot,top,col;int head[wx],dfn[wx],low[wx],st[wx],belong[wx],size[wx],t[wx],flag[wx];struct e{int Nxt,to;}    edge[wx*2];void Add (int from,int to) {Edge[++num].nxt=head[from];    Edge[num].to=to; Head[from]=num;}    void Tarjan (int u) {dfn[u]=low[u]=++tot;    St[++top]=u;        for (int i=head[u];i;i=edge[i].nxt) {int v=edge[i].to;            if (!dfn[v]) {Tarjan (v);        Low[u]=min (Low[u],low[v]);        } else if (!belong[v]) {low[u]=min (low[u],dfn[v]);        }} if (Dfn[u]==low[u]) {belong[u]=++col;        Size[col]=1;          while (st[top]!=u) {belong[st[top]]=col;  size[col]++;        top--;    } top--;    }}int Main () {n=read (); M=read ();        for (int i=1,x,y,z;i<=m;i++) {x=read (); Y=read (); Z=read ();        if (z==1) Add (x, y);    else Add (x, y), add (y,x);    } for (int i=1;i<=n;i++) {if (!dfn[i]) Tarjan (i);    } for (int i=1;i<=col;i++) Ans=max (Ans,size[i]);    for (int i=1;i<=col;i++) if (Size[i]==ans) flag[i]=1;    memset (t,0x3f,sizeof T);        for (int i=1;i<=n;i++) {if (Flag[belong[i]]) {t[belong[i]]=min (t[belong[i]],i);    }} int now=0x3f3f3f3f,pos=0;        for (int i=1;i<=col;i++) {if (Now>t[i]) {now=t[i];p os=i;    }} printf ("%d\n", ans);    for (int i=1;i<=n;i++) {if (Belong[i]==pos) printf ("%d", I);  } return 0;}

Kamishirasawa tone on the indented point

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.