Http://acm.sdut.edu.cn/sdutoj/problem.php? Action = showproblem & problemid = 2894
Because of carelessness, I didn't have a at noon. The question is "2000000 edge undirected graphs", but I opened 2000000 in the array. It's a damn thing. When I saw the status of others' A, the memory was twice as large as mine, I instantly knew that my hand was broken, obviously 4000000,
But what I don't understand is that spfa is an improved version of be, but why is it 7100 Ms.
# Include <iostream> # include <stdio. h> # include <string. h> # include <stdlib. h> # define n 10000001 using namespace STD; struct node {int X, Y, W;} edge [4000002]; int dis [500002]; int n, m, S, e; int T, flag; void add (INT X1, int Y1, int W1) {edge [T]. X = x1; edge [T]. y = Y1; edge [t ++]. W = W1;} void B () {for (INT I = 0; I <= N; I ++) dis [I] = N; DIS [s] = 0; for (INT I = 1; I <= n-1; I ++) {flag = 0; For (Int J = 0; j <t; j ++) {If (DIS [edge [J]. x] + edge [J]. W <dis [edge [J]. y]) {flag = 1; DIS [edge [J]. y] = dis [edge [J]. x] + edge [J]. W ;}} if (flag = 0) break;} printf ("% d \ n", DIS [e]);} int main () {int XX, YY, ZZ; while (scanf ("% d", & N, & M )! = EOF) {T = 0; while (M --) {scanf ("% d", & XX, & YY, & zz); add (XX, YY, ZZ); add (YY, XX, ZZ);} scanf ("% d", & S, & E); B ();} return 0 ;} /************************************ Problem ID: sdut OJ 2894 User name: zlh130205 result: accepted take Memory: 49344 K take time: 710 Ms submit time: 13:32:27 **************************************/