/*
题目大意:求出点1到所有点的最短路之和 + 所有点到点1的最短路之和
这个解题思路非常巧妙,要求所有点到1的最短路径,则把所有边反向,然后求1的单源点最短路即可
*/
//ps:poj不按套路出牌啊,dis居然那么大,搞的和超出了int
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
const int mn=1000005,mm=1000005;
struct Edge{
int to,w,next;
}edges[2*mm];
int h1[mn],h2[mn],tot,n,m,dis[mn];
bool inq[mn];
void add1(int u,int v,int w)
{
edges[tot].to=v;
edges[tot].w=w;
edges[tot].next=h1[u];
h1[u]=tot++;
}
void add2(int u,int v,int w)
{
edges[tot].to=v;
edges[tot].w=w;
edges[tot].next=h2[u];
h2[u]=tot++;
}
long long spfa(int* head)
{
//求1的单源点最短路
//memset(dis,6,(n+1)*sizeof(int));
for(int i=1;i<=n;++i)
dis[i]=2e9;
memset(inq,0,(n+1)*sizeof(bool));
dis[1]=0,inq[1]=true;
deque<int> q;
q.push_back(1);
whi