社区讨论
0pt求助
P1726上白泽慧音参与者 1已保存回复 0
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @m2fikrjf
- 此快照首次捕获于
- 2024/10/19 10:02 去年
- 此快照最后确认于
- 2024/10/19 11:59 去年
rt
CPP#include <bits/stdc++.h>
using namespace std;
namespace Tarjan{
const int MAXN=5e3+10,MAXM=5e4+10;
int head[MAXN],to[MAXM<<1],nxt[MAXM<<1],val[MAXM<<1];
int dfn[MAXN],low[MAXN];
int cnt,tot;
bool vis[MAXM<<1];
stack<int> st;
set<int> ans[MAXN];
inline void add(int x,int y,int z){
to[++cnt]=y,val[cnt]=z;
nxt[cnt]=head[x],head[x]=cnt;
}
inline void add_edge(int x,int y,int z){
add(x,y,z);
add(y,x,z);
}
inline void tarjan(int x){
dfn[x]=low[x]=++tot;
st.push(x),vis[x]=1;
for(int i=head[x];i;i=nxt[i]){
int y=to[i];
if(!dfn[y]){
tarjan(y);
low[x]=min(low[x],low[y]);
}else{
if(vis[y])
low[x]=min(low[x],dfn[y]);
}
}
if(low[x]==dfn[x]){
++tot;
while(1){
int tmp=st.top();
st.pop();
vis[tmp]=0;
ans[tot].insert(tmp);
if(tmp==x) break;
}
}
}
inline bool cmp(set<int> a,set<int> b) {
return !(lexicographical_compare(a.begin(),a.end(),b.begin(),b.end()));
}
}using namespace Tarjan;
int main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
int n,m; cin>>n>>m;
for(int i=1;i<=m;++i){
int x,y,op; cin>>x>>y>>op;
if(op==1) add(x,y,114);
else add_edge(x,y,114);
}
for(int i=1;i<=n;++i) if(!dfn[i]) tarjan(i);
sort(ans+1,ans+1+tot,cmp);
cout<<ans[1].size()<<'\n';
for(auto it=ans[1].begin();it!=ans[1].end();++it) cout<<*it<<' ';
return 0;
}
回复
共 0 条回复,欢迎继续交流。
正在加载回复...