【luogu P1726 上白泽慧音】 题解
题目链接: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;
}
【luogu P1726 上白泽慧音】 题解的更多相关文章
- Luogu P1726 上白泽慧音
这显然是一道求强连通分量(SCC)的题目. 只要你正常,都知道应该写Tarjan. 然后(假装会写Tarjan),其实我当然不会.但是求SCC还有另一个算法.复杂度和Tarjan一样,只不过常数大了点 ...
- 洛谷P1726 上白泽慧音(Tarjan强连通分量)
P1726 上白泽慧音 题目描述 在幻想乡,上白泽慧音是以知识渊博闻名的老师.春雪异变导致人间之里的很多道路都被大雪堵塞,使有的学生不能顺利地到达慧音所在的村庄.因此慧音决定换一个能够聚集最多人数的村 ...
- P1726 上白泽慧音 tarjan 模板
P1726 上白泽慧音 这是一道用tarjan做的模板,要求找到有向图中最大的联通块. #include <algorithm> #include <iterator> #in ...
- 洛谷P1726 上白泽慧音 [Tarjan]
题目传送门 上白泽慧音 题目描述 在幻想乡,上白泽慧音是以知识渊博闻名的老师.春雪异变导致人间之里的很多道路都被大雪堵塞,使有的学生不能顺利地到达慧音所在的村庄.因此慧音决定换一个能够聚集最多人数的村 ...
- CODEVS——T1332 上白泽慧音 || 洛谷——P1726 上白泽慧音
http://codevs.cn/problem/1332/|| https://www.luogu.org/problem/show?pid=1726#sub 时间限制: 1 s 空间限制: 1 ...
- 洛谷P1726 上白泽慧音
题目描述 在幻想乡,上白泽慧音是以知识渊博闻名的老师.春雪异变导致人间之里的很多道路都被大雪堵塞,使有的学生不能顺利地到达慧音所在的村庄.因此慧音决定换一个能够聚集最多人数的村庄作为新的教学地点.人间 ...
- P1726 上白泽慧音
题目描述 在幻想乡,上白泽慧音是以知识渊博闻名的老师.春雪异变导致人间之里的很多道路都被大雪堵塞,使有的学生不能顺利地到达慧音所在的村庄.因此慧音决定换一个能够聚集最多人数的村庄作为新的教学地点.人间 ...
- 洛谷 P1726 上白泽慧音
题目描述 在幻想乡,上白泽慧音是以知识渊博闻名的老师.春雪异变导致人间之里的很多道路都被大雪堵塞,使有的学生不能顺利地到达慧音所在的村庄.因此慧音决定换一个能够聚集最多人数的村庄作为新的教学地点.人间 ...
- P1726 上白泽慧音(0分)
题目描述 在幻想乡,上白泽慧音是以知识渊博闻名的老师.春雪异变导致人间之里的很多道路都被大雪堵塞,使有的学生不能顺利地到达慧音所在的村庄.因此慧音决定换一个能够聚集最多人数的村庄作为新的教学地点.人间 ...
随机推荐
- IE Error: '__doPostBack' is undefined 问题解决
突然遇到个很奇怪的BUG,翻页控件,其他浏览器一切正常,IE无法翻页,会提示 '__doPostBack' is undefined 后来搜索发现: [原文發表地址] Bug and Fix: ASP ...
- 案例44-crm练习新增客户使用struts2
1 src下配置文件 1 struts.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYP ...
- TOJ 3031 Multiple
Description a program that, given a natural number N between 0 and 4999 (inclusively), and M distinc ...
- 如何去除表单元素获得焦点时的外边框:outline (轮廓)
我们在做制作表单页面时,经常会需要消除表单元素带来的边框,这时候我们需要用到两个属性: 1.表单元素未激活状态下的边框,不实现边框: border:none; 2.表单元素获得焦点时的轮廓,隐藏轮廓: ...
- nyoj 12——喷水装置二——————【贪心-区间覆盖】
喷水装置(二) 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 有一块草坪,横向长w,纵向长为h,在它的橫向中心线上不同位置处装有n(n<=10000)个点状的 ...
- java File delete()执行失败原因(转)
java.io.File里的delete操作很实用也很常用,可以用来删除单独的文件和某一目录.但有时候会出现delete失败的情况,出现这种情况的原因一般有以下几种:1.删除时还有其他程序在使用该文件 ...
- 利用Filter实现session拦截
1.在web.xml中配置 <!-- Session监听器 --> <filter> <filter-name>sessionValidateFilter</ ...
- 使用Access作数据库
import java.sql.*; public class ConnectAccess { public static void main(String args[]){ ConnectAcces ...
- win 环境下 node.js环境变量
在win 环境下 node.js环境变量有两种情况: (1)开发环境(development):开发环境是程序猿们专门用于开发的服务器,配置可以比较随意, 为了开发调试方便,一般打开全部错误报告. ...
- mysql无法连接Can't create a new thread (errno 11)
问题描述: 今天本地navicat连接服务器mysql出错 ,提示ERROR 1135: Can't create a new thread (errno 11); if you are not ou ...