码迷,mamicode.com
首页 > 其他好文 > 详细

炸铁路

时间:2019-07-08 21:00:32      阅读:124      评论:0      收藏:0      [点我收藏+]

标签:模板   min   algorithm   names   name   include   struct   gate   下标   

[Time Gate]

https://www.luogu.org/problemnew/show/P1656

【解题思路】

割点+桥模板题

关键在于排序用下标排序记录

【code】

#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std; 
struct Node{ 
    int s; 
    int t;
    int nxt; 
}a[1000005];
inline int Min(int a,int b){
    return a<b?a:b;
}
int n,m,cnt,tot; 
int dfn[1000005],low[1000005],head[1000005],p[1000005]; 
inline void Add(int u,int v){ a[++cnt].s=u; a[cnt].t=v; a[cnt].nxt=head[u]; head[u]=cnt; return ; } 
inline void Tarjan(int u,int fa){ 
     dfn[u]=low[u]=++cnt; 
     for(register int i=head[u];i;i=a[i].nxt){ 
         int v=a[i].t; 
        if(!dfn[v]){
             Tarjan(v,u); 
             low[u]=Min(low[u],low[v]);
              if(dfn[u]<low[v])p[++tot]=i; 
        } 
      else if(v!=fa) low[u]=Min(low[u],dfn[v]);
    }     
} 
inline bool cmp(int x,int y){ 
    if(a[x].s==a[y].s)return a[x].t<a[y].t; 
    return a[x].s<a[y].s;
}
int main(){ 
    scanf("%d%d",&n,&m); 
    for(register int i=1;i<=m;i++){ 
        int a,b;
        scanf("%d%d",&a,&b); 
        Add(a,b); 
        Add(b,a); 
    } 
    for(register int i=1;i<=n;i++)
         if(!dfn[i])Tarjan(i,0); 
    sort(p+1,p+tot+1,cmp);
    for(register int i=1;i<=tot;i++) 
        printf("%d %d\n",a[p[i]].s,a[p[i]].t); 
    return 0;
}

 

炸铁路

标签:模板   min   algorithm   names   name   include   struct   gate   下标   

原文地址:https://www.cnblogs.com/66dzb/p/11153772.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!