题目链接:https://www.luogu.org/problemnew/show/P1726

#include <stack>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 50000 + 10;
int n, m, root;
struct edge{
int from, to, next;
}e[maxn<<2];
int head[maxn], cnt;
int dfn[maxn], low[maxn], color[maxn], tim, num, tong[maxn];
bool vis[maxn];
stack<int> s;
void add(int u, int v)
{
e[++cnt].from = u;
e[cnt].next = head[u];
e[cnt].to = v;
head[u] = cnt;
}
void tarjan(int x)
{
dfn[x] = low[x] = ++tim;
s.push(x); vis[x] = 1;
for(int i = head[x]; i != -1; i = e[i].next)
{
int v = e[i].to;
if(!dfn[v])
{
tarjan(v);
low[x] = min(low[x], low[v]);
}
else if(vis[v])
{
low[x] = min(low[x], low[v]);
}
}
if(dfn[x] == low[x])
{
color[x] = ++num;
vis[x] = 0;
while(s.top() != x)
{
color[s.top()] = num;
vis[s.top()] = 0;
s.pop();
}
s.pop();
}
}
int main()
{
memset(head, -1, sizeof(head));
scanf("%d%d",&n,&m);
for(int i = 1; i <= m; i++)
{
int u, v, w;
scanf("%d%d%d",&v,&u,&w);
if(w == 1)
{
add(u, v);
}
else
{
add(u, v), add(v, u);
}
}
for(int i = 1; i <= n; i++)
if(!dfn[i]) tarjan(i);
for(int i = 1; i <= n; i++)
tong[color[i]]++;
int ans = -1, flag;
for(int i = 1; i <= num; i++)
{
if(ans < tong[i])
{
ans = tong[i];
flag = i;
}
}
printf("%d\n",ans);
for(int i = 1; i <= n; i++)
if(color[i] == flag) printf("%d ",i);
return 0;
}

最新文章

  1. C#获取屏幕鼠标所指点的颜色
  2. Union-Find 检测无向图有无环路算法
  3. Javascript本质第一篇:核心概念
  4. 移动前端开发-单页应用(spa)模型
  5. Visual Studio 2013支持Xamarin的解决方案
  6. test 2017-1-5
  7. ffmpeg 音频转换: use ffmpeg convert the audio from stereo to mono without changing the video part
  8. 初学C++之自定义类型名简化
  9. [最近公共祖先] POJ 3728 The merchant
  10. C++概念整理
  11. 推荐一款C#反编译软件(开源)
  12. 同一个tomcat多个web应用共享session
  13. css pre如果同时运用了css的border-radius、 overflow两个属性且标签中内容太多时,外部div滚动条在firefox下滚动时很卡
  14. ASP.NET动态引用WebService接口
  15. 转自scutan 常用的Linux编程库
  16. 在MVC中使用rdlc格式的报表
  17. 项目Beta冲刺Day2
  18. ABB机器人基础培训资料整理与总结
  19. js判断对象是否为空
  20. 01day

热门文章

  1. underscore javascript工具库支持seajs模块化
  2. 数据挖掘:提取百度知道QA中的影视信息
  3. 通过js操作样式(评分)
  4. javascript小数相减出现一长串的小数位数
  5. mogondb简介
  6. css sticky footer布局
  7. PHP基础--strtr和str_replace字符替换函数
  8. 自整定模糊PID算法的理论
  9. GitHub无法push的问题
  10. SVN学习——简单入门之创建仓库、导入、检出(一)