Main topic:
Give you an s,t diagram, and then a one-stop representation of the beginning and end, and then enter the N,m,s,t, the M-bar without a phase into a set of L, so that any one of the set of the edge is removed, can not reach s (or S to T, specifically do not remember, but almost ...). ), and then you want to find the largest l, and then output each edge set.
Problem Solving Ideas:
First see to make unreachable, I think of the network flow, but later thought to find, actually very simple.
First run the shortest path with S as the starting point, and then get a dis[t] that represents the shortest distance from S to T, and then l=dis[t]
Next is to group the edges, for i=1~dis[t], Edge <u,v> (we assume dis[u]<=dis[v]) if satisfies dis[u]+1=dis[v], then the edge is added to the Dis[v] collection, The rest of the unsatisfied side just put on the just fine.
The correctness of the specific algorithm is not given proof.
AC Code:
#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <algorithm > #include <iostream> #include <vector> #define MAX (a) (a) > (b)? A):(B) #define MIN (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));d is[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<dis[bian[p].num] && hash[bian[p].num ]==0) {hash[bian[p].num]=1;dui[++duip]=bian[p].num;dis[bian[p].num]=dis[dui[i]]+1;}} hash[dui[i]]=0;} return;} int main () {scanf ("%d%d%d%d", &n,&m,&s,&t), for (int i=1;i<=m;i++) {int p,q;scanf ("%d%d", &p, &Q); ADD (p,q,i*2-1); ADD (q,p,i*2); g[i][0]=P;g[i][1]=q;} SPFA (); vector <int> 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 ()), and for (int j=ans[i].size () -1;j>=0 ; j--) printf ("%d%c", ans[i][j],j==0? \ n ': ');} return 0;}
Sgu213-strong Defence