记录编号 |
172707 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[東方S1] 上白泽慧音 |
最终得分 |
100 |
用户昵称 |
forever |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.253 s |
提交时间 |
2015-07-26 11:33:04 |
内存使用 |
79.10 MiB |
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
using namespace std;
struct dd
{
int kaishi;
int zhong;
int next;
}jie[120000];
int Min(int h,int y)
{
if(h>y) return y;
return h;
}
struct gu
{
int a[4500];
int shu;
}jiege[4502];
int m,y,t,ao[4502];
int comp(const gu & ab,const gu & b)
{
if(ab.shu>b.shu) return 1;
if(ab.shu<b.shu) return 0;
if(ab.shu==b.shu) return ab.a[1]<b.a[1];
}
int v[5001],times,dfn[5001],low[5001],n,x;
int tot,num,st[4502];
int head[5001],top;
void add(int x,int y)
{
tot++;
jie[tot].kaishi=x;
jie[tot].zhong=y;
jie[tot].next=head[x];
head[x]=tot;
}
void tar(int y)
{
times++;
dfn[y]=low[y]=times;
st[++top]=y,v[y]=1;
for(int i=head[y];i!=-1;i=jie[i].next)
{
int yu=jie[i].zhong;
if(!dfn[yu])
{
tar(yu);
low[y]=Min(low[y],low[yu]);
}
else
if(v[yu])
{
low[y]=Min(low[y],dfn[yu]);
}
}
if(low[y]==dfn[y])
{
++num;
memset(ao,0,sizeof(ao));
int yulin;
do{
yulin=st[top--];
v[yulin]=0;
jiege[num].shu++;
ao[jiege[num].shu]=yulin;
}while(yulin!=y);
sort(ao+1,ao+jiege[num].shu+1);
for(int i=1;i<=jiege[num].shu;++i)
{
jiege[num].a[i]=ao[i];
//cout<<ao[i]<<endl;
}
}
}
void work()
{ //sort(jiege.a+1,jiege.a+jiege)
sort(jiege+1,jiege+num+1,comp);
printf("%d\n",jiege[1].shu);
for(int i=1;i<=jiege[1].shu;++i)
printf("%d ",jiege[1].a[i]);
}
int main()
{
freopen("classroom.in","r",stdin);
freopen("classroom.out","w",stdout);
memset(head,-1,sizeof(head));
scanf("%d%d",&n,&m);
for(int i=1;i<=m;++i)
{
scanf("%d%d%d",&x,&y,&t);
if(t==1)
add(x,y);
if(t==2)
{
add(x,y);
add(y,x);
}
}
for(int i=1;i<=n;++i)
if(!dfn[i])
tar(i);
work();
//while(1);
}