SPFA twice. Calculates the sum of the least short circuit between the come and the return.
Using Dijkstra + adjacent matrix is indeed easy to write + easy to exchange, but there are 1000000 points, and the matrix cannot be opened.
D1 [] is 1 ~ N.
Swap the neighboring points of all edges.
D2 [] is 1 ~ N.
All are added as the desired answer.
Sadly, SPFA "HDU 1535" AC is used, but POJ 1511 is the same as POJ.
Then the obsessive-compulsive disorder keeps testing.
Prices are positive integers the sum of which is smaller than 1000000000
Int can be used. HDU is like this.
Then I changed the sum of POJ to long. Or WA.
Then I found that there was a problem with INF, and 0 xfffffff was not enough. Then change it to the maximum value of 0x7fffff int, AC.
POJ data is awesome. I do not want to read the question at all.
#include
#include
#include
#include
#include#include
#include
#include
#include
#include
#include
#include
#define INF 0x7fffffff#define eps 1e-6using namespace std;int n,m;struct lx{ int v,d;};int dis[1000001];bool vis[1000001];int e[1000001];vector
g[1000001];void swapg(){ for(int i=1;i<=n;i++) e[i]=g[i].size(); for(int i=1;i<=n;i++) { int u,v,d; lx now; u=i; for(int j=0;j
q; dis[1]=0,vis[1]=1; q.push(1); while(!q.empty()) { int u=q.front();q.pop(); vis[u]=0; for(int j=e[u];j
dis[u]+d) { dis[v]=dis[u]+d; if(!vis[v]) { vis[v]=1; q.push(v); } } } } int ans=0; //long long for(int i=1;i<=n;i++) ans+=dis[i]; return ans;}int main(){ int t; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); int u,v,d; lx now; for(int i=1;i<=n;i++) g[i].clear(); while(m--) { scanf("%d%d%d",&u,&v,&d); now.d=d; now.v=v; g[u].push_back(now); } memset(e,0,sizeof(e)); int dis1=SPFA(n); //long long swapg(); int dis2=SPFA(n); //long long printf("%d\n",dis1+dis2); // lld% }}