HDU 3313 Key Vertex Those AC codes are basically wrong!

Source: Internet
Author: User

8 91 40 22 44 53 52 66 30 77 10 5 This set of data, the answer should be 2,  the online solution is output 3 Their search method is not correct
First look at their description of the error algorithm: " first find an arbitrary path from S to T, if there is no road, then cut the number of N, if found a path, the point on this path is marked out, first clear a point, cut points will certainly not be on the point outside the path, because after removing the outside point, There's still a path that's just that way. So now it's time to see if each point on the path is a cutting point. As long as the point on the path is removed, and then from the BFS, the path of the point can not go, so that the BFS record can be visited to the farthest point on the path is ans, if ans equals t, then only two cut points s and T, if the BFS after the end ans is not equal to T, then ans is a cut point. It is impossible to get to the point after the point has been removed. Then proceed with the BFS from ans until access to T. "
The problem is that the BFS-to-ans is not necessarily a key point!    
Suppose we numbered the points on the shortest path based on the distance from the starting point, then S is 0. From S search to ans, assuming that the ANS number is a, if there is a point between 0 and a on the path that can be BFS to a point ans2, number B, and B > A, then ans is not a key point! 
The right thing to do is to bfs! between 0 and a. The correct code is as follows:
#include <stdio.h> #include <string.h> #include <ctype.h> #include <math.h> #include <string > #include <vector> #include <queue> #include <algorithm>using namespace std;void fre () {freopen (" T.txt "," R ", stdin);} #define LS o<<1#define rs o<<1|1#define MS (x, y) memset (x,y,sizeof (×)) typedef long Long Ll;typedef unsigned lo ng long ul;typedef unsigned int ui;const int INF = 0x3f3f3f3f;const int dir[4][2] = {1,0,0,1,-1,0,0,-1};const int maxn = 1    00010;const int MAXM = 300010;//input Hang char in;int neg;inline void int (int &x) {NEG = 0;    while (!isdigit (In=getchar ())) if (in== '-') NEG = 1;    x = in-' 0 ';    while (IsDigit (In=getchar ())) x = x*10+in-' 0 '; if (NEG) x =-X;} struct edge{int v,nxt;} E[maxm];int tot,head[maxn];void addedge (int u,int v) {E[tot] = (edge) {V,head[u]}; head[u] = tot++;} int N,m,end;int dep[maxn],pre[maxn],q[maxn],path[maxn],in[maxn];bool vis[maxn];bool bfs (int s,int t) {for (int i = 0; i < n; ++i) pre[i] = deP[i] =-1;    int L = 0, R = 0; q[r++] = s;    Dep[s] = 0;        while (L < R) {int u = q[l++];            for (int i = head[u]; i =-1; i = e[i].nxt) {int v = E[I].V;            if (dep[v]! =-1) continue; PRE[V] = u;            DEP[V] = Dep[u] + 1;            if (v = = t) return 1;        q[r++] = v; }} return 0;}    int BFS2 (int s) {int L = 0, R = 0,max = 0; q[r++] = s;    Vis[s] = 1;        while (L < R) {int u = q[l++];            for (int i = head[u]; i =-1; i = e[i].nxt) {int v = E[I].V;                if (In[v]) {if (In[v] > max) max = in[v];            Continue            } if (Vis[v]) continue;            VIS[V] = 1;            q[r++] = v;        if (max = = End) return max; }} return MAX;} int solve () {tot = 0;    MS (head,-1);    for (int i = 0; i < n; ++i) vis[i] = In[i] = 0;    int u,v,s,t;        while (m--) {int (u); int (v);   Addedge (U,V); } Int (s);    Int (t);    if (!bfs (s,t)) return n;  u = t;    End = Dep[t];    while (U =-1) in[u] = End, path[end--] = u, u = pre[u];    End = Dep[t];    int ans = 0,l = 0, R = 0;        while (r! = End) {if (L = = R) ans++;        R = Max (R,BFS2 (path[l));    l++; } return ans+1;} int main () {while (~scanf ("%d%d", &n,&m)) printf ("%d\n", Solve ());}

HDU 3313 Key Vertex Those AC codes are basically wrong!

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.