Maximum stream of hdu 4975 and determination of its uniqueness (directed graph ring judgment algorithm upgrade)
Let's review the largest stream at that time .. Try again... I don't want to talk about the classic solution anymore .. This question mainly refers to the pitfall time, with 10 submissions of 7 tle.
Ring judgment, once using a simple dfs method, this time it's tle! I felt that I could not time out to use a very embarrassing dinic. I firmly believed that the ring was slow. So I learned how to delete a vertex or edge when breaking the ring! If you go in from a certain point, if all the edges of the point have been traversed and still fail to return, then the store will no longer enter (this simple way should be thought! Stupid !) Delete edges only at the beginning, or tle! Nb! So I deleted and deleted the edge myself. It took a moment to 156 ms, and the first 5 were there!
# Include
# Include
# Include
# Include
# Include
Using namespace std; const int maxv = 1200; const int maxe = 2*501*501 + 2000; const int inf = 0x3f3f3f3f; int n, m; int allsumn = 0, allsumm = 0; int nume = 0; int e [maxe] [3]; int head [maxv]; bool flag; void inline adde (int I, int j, int c) {e [nume] [0] = j; e [nume] [1] = head [I]; head [I] = nume; e [nume ++] [2] = c; e [nume] [0] = I; e [nume] [1] = head [j]; head [j] = nume; e [nume ++] [2] = 0;} int lev[ maxv]; int vis [maxv]; int ss = 0; int tt = 0; bool bfs () {memset (lev, 0, sizeof (lev)); memset (vis, 0, sizeof (vis); queue
Q; q. push (ss); vis [ss] = 1; while (! Q. empty () {int cur = q. front (); q. pop (); for (int I = head [cur]; I! =-1; I = e [I] [1]) {int v = e [I] [0]; if (e [I] [2]> 0 &&! Vis [v]) {lev[ v] = lev[ cur] + 1; // if (v = tt) return 1; // This sentence is not added, faster q. push (v); vis [v] = 1 ;}} return vis [tt] ;}int dfs (int u, int minf) {if (u = tt | minf = 0) return minf; int sumf = 0, f; for (int I = head [u]; I! =-1 & minf; I = e [I] [1]) {int v = e [I] [0]; if (lev_v] = lev_u] + 1 & e [I] [2]> 0) {f = dfs (v, e [I] [2]