Sgu213-Strong (Defense)

Source: Internet
Author: User

Sgu213-Strong (Defense)

Question:

Give you an undirected graph, and then a second, t represents the start point and the end point, then input n, m, s, t, and divide m pieces of undirected edges into L sets, so that after the edge of any set is removed, it cannot reach s from t (or s to t. I don't remember it, but it's similar .....), Then you need to find the largest L and then output each edge set.


Solution:

First, I thought about the network stream, but later I thought It was actually very simple.

Run the shortest path at the starting point of s, and a dis [t] indicates the shortest distance from s to t, then L = dis [t]

Group the edge ~ Dis [t], edges (Assume that dis [u] <= dis [v]) If dis [u] + 1 = dis [v] is satisfied, add this edge to the dis [v] collection, and place other unsatisfied edges as needed.

The correctness of the specific algorithm is not proved.


AC code:

#include 
 
  #include 
  
   #include 
   
    #include 
    
     #include #include 
     
      #include 
      
       #define MAX(a,b) ((a)>(b)?(a):(b))#define MIN(a,b) ((a)>(b)?(b):(a))using namespace std;int n,m,s,t;struct bian_{int num;int next;}bian[160010]={{0,0}};int g[160010][2]={{0}};int First[410]={0};int dis[410]={0};int hash[410]={0};int dui[1000010]={0};inline void Add(int p,int q,int k){bian[k].num=q;bian[k].next=First[p];First[p]=k;return;}void SPFA(){int duip=1;memset(dis,0x3f3f3f3f,sizeof(dis));dis[s]=0;dui[duip]=s;hash[s]=1;for(int i=1;i<=duip;i++){for(int p=First[dui[i]];p!=0;p=bian[p].next){if(dis[dui[i]]+1
       
         ans[410];for(int i=1;i<=m;i++){int p=dis[g[i][0]],q=dis[g[i][1]];if(p>q) swap(p,q);if(q==p+1){if(q>=dis[t])ans[dis[t]].push_back(i);else ans[q].push_back(i);}else ans[dis[t]].push_back(i);}printf("%d\n",dis[t]);for(int i=1;i<=dis[t];i++){printf("%d ",ans[i].size());for(int j=ans[i].size()-1;j>=0;j--)printf("%d%c",ans[i][j],j==0?'\n':' ');}return 0;}
       
      
     
    
   
  
 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.