题目大意:
给定一个起点,求以其余所有点分别为必经点的最短回路之和。思路:
建立反向图,在正反图上分别跑一遍Dijkstra,最后求和即可。注意数据规模,要开long long不然会WA,只能拿25分。1 #include2 #include 3 #include 4 #include 5 inline int getint() { 6 register char ch; 7 while(!isdigit(ch=getchar())); 8 register int x=ch^'0'; 9 while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0');10 return x;11 }12 const long long inf=0x7fffffffffffffff;13 const int V=1000001;14 struct Edge {15 int to;16 long long w;17 };18 std::vector e1[V],e2[V];19 inline void add_edge(std::vector *e,const int u,const int v,const long long w) {20 e[u].push_back((Edge){v,w});21 }22 struct Vertex {23 int id;24 long long dis;25 bool operator > (const Vertex &another) const {26 return dis>another.dis;27 }28 };29 int n;30 long long dis1[V],dis2[V];31 __gnu_pbds::priority_queue > q;32 __gnu_pbds::priority_queue >::point_iterator p[V];33 const int s=1;34 inline void Dijkstra(long long *dis,std::vector *e) {35 q.clear();36 for(register int i=1;i<=n;i++) {37 p[i]=q.push((Vertex){i,dis[i]=(i==s)?0:inf});38 }39 while(q.top().dis!=inf) {40 int x=q.top().id;41 for(register unsigned i=0;i