记录编号 |
343999 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[東方S1] 上白泽慧音 |
最终得分 |
100 |
用户昵称 |
sxysxy |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.045 s |
提交时间 |
2016-11-09 20:23:27 |
内存使用 |
0.54 MiB |
显示代码纯文本
#include <cstdio>
#include <cstdlib>
#include <cstdarg>
#include <cstring>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
#include <functional>
using namespace std;
#define N 5002
int n, m;
int low[N], dfn[N], stamp;
int scc[N], scc_cnt;
vector<int> sccp[N];
int stk[N<<1], top;
vector<int> G[N];
void tarjan(int u)
{
low[u] = dfn[u] = ++stamp;
stk[top++] = u;
for(int i = 0; i < G[u].size(); i++)
{
int to = G[u][i];
if(!dfn[to])
{
tarjan(to);
low[u] = min(low[u], low[to]);
}else if(!scc[to])
low[u] = min(low[u], dfn[to]);
}
if(dfn[u] == low[u])
{
int x;
scc_cnt++;
while(true)
{
x = stk[--top];
scc[x] = scc_cnt;
sccp[scc_cnt].push_back(x);
if(u == x || !top)break;
}
}
}
void calc()
{
for(int i = 1; i <= n; i++)if(!dfn[i])tarjan(i);
}
int rank[N];
bool cmp(int a, int b)
{
return sccp[a].size()>sccp[b].size() || (sccp[a].size()==sccp[b].size() && sccp[a] < sccp[b]);
}
int main()
{
freopen("classroom.in", "r", stdin);
freopen("classroom.out", "w", stdout);
scanf("%d %d", &n, &m);
for(int i = 1; i <= m; i++)
{
int x, y, t;
scanf("%d %d %d", &x, &y, &t);
G[x].push_back(y);
if(t == 2)G[y].push_back(x);
}
calc();
for(int i = 1; i <= scc_cnt; i++)sort(sccp[i].begin(), sccp[i].end());
for(int i = 1; i <= scc_cnt; i++)rank[i] = i;
sort(rank+1, rank+1+scc_cnt, cmp);
vector<int> &ans = sccp[rank[1]];
printf("%d\n", ans.size());
for(int i = 0; i < ans.size(); i++)
printf("%d ", ans[i]);
puts("");
return 0;
}