codevs 2604 舞会邀请 tarjan
来源:互联网 发布:高晓松酒驾 知乎 编辑:程序博客网 时间:2024/05/16 11:38
题目:
http://codevs.cn/problem/2604/
数组开小了,WA了3个点;
并查集在codevs可以AC,但在洛谷上只有82分;
codevs真的要没落了吗?<-_<-
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<stack>using namespace std;const int MAXN=1000001;int fst[MAXN],nxt[MAXN];int ru[MAXN],low[MAXN],dfn[MAXN],scc[MAXN];int tim,tot,n,ans,cnt;stack<int>s;struct hh { int from,to; }ma[MAXN];void build(int f,int t){ ma[++tot]=(hh){f,t}; nxt[tot]=fst[f]; fst[f]=tot;}void tarjan(int x){ low[x]=dfn[x]=++tim; s.push(x); for(int i=fst[x];i;i=nxt[i]) { int v=ma[i].to; if(!dfn[v]) tarjan(v),low[x]=min(low[x],low[v]); else if(!scc[v]) low[x]=min(low[x],dfn[v]); } if(low[x]==dfn[x]) { cnt++; while(1) { int u=s.top(); s.pop(),scc[u]=cnt; if(u==x) return; } } return;}void solve(){ scanf("%d",&n); for(int i=1;i<=n;i++) { int num=0; while(1) { scanf("%d",&num); if(!num) break; build(i,num); } } for(int i=1;i<=n;i++) if(!dfn[i]) tarjan(i); for(int i=1;i<=tot;i++) { if(scc[ma[i].from]!=scc[ma[i].to]) ru[scc[ma[i].to]]++; } for(int i=1;i<=cnt;i++) if(!ru[i]) ans++; cout<<ans; return;}int main(){ solve(); return 0;}
阅读全文
0 0
- codevs 2604 舞会邀请 tarjan
- codevs 2604 舞会邀请(tarjan)
- codevs 舞会邀请(Tarjan)
- 【codevs 2604】舞会邀请
- codevs 2604 舞会邀请(tarjan缩点BFS)
- codevs 舞会邀请
- Codevs 2064 舞会邀请
- Codevs2604舞会邀请
- codevs 没有上司的舞会
- 【codevs】1506 传话 Tarjan
- codevs-2822 (Tarjan)
- codevs 2822(tarjan)
- [Vijos P1022]Victoria的舞会2 Tarjan
- Codevs P1380 没有上司的舞会
- CODEVS 1380 没有上司的舞会
- CODEVS 1380没有上司的舞会
- 【codevs 1380】没有上司的舞会
- CODEVS 1380 没有上司的舞会
- [机器学习实战] Ubuntu 16.04 + NVIDIA 384 + OpenCV 3.1.0 + CUDA 8.0 + cuDNN 5.1 踩坑记录
- Prim和Kruskal求最小生成树
- 递归算法的时间复杂度分析
- 344. Reverse String
- Could not obtain transaction-synchronized Session for current thread
- codevs 2604 舞会邀请 tarjan
- SpringMVC重要接口(二)HandlerMethodReturnValueHandler
- 使用OpenCV进行目标检测的注意事项
- 0基础lua学习(十一)table
- (递归)逆波兰表达式
- Python字典集合数据结构深入理解
- object
- LitePal使用UUID作为主键
- (Neighbourhood Components Analysis) NCA 近邻成分分析的学习