Link
Topic Description Description
Sail Ocean to defeat the Reverend sister Sauce, at all costs through a variety of means to get the legendary props "れいじまいご" to release energy to make the world full of the majestic air and energy field sailing. However, the energy released by "れいじまいご" can only exist in a very small area, in order to make the effect can be scattered around the world, sail Ocean decided to emulate the mind manipulator-Yuri, in the World built n "れいじまいご ベクトル becomes switch" so that its energy field can be opened around the world.
According to computer calculations, most of these n sites are very remote towns. Therefore, the road between is not the capital is unimpeded. Between these areas through the R road connection, in order to make it easy to travel between, sailing ocean Tel also help sail Ocean produced a p space tunnel, sailing ocean called "Time と Gate". Each road I or "Time と space Gate" I connects the area AI to Bi, which is spent for CI. The roads are two-way, ranging from Ai to bi, from bi to AI, and the cost is CI. However, "Time と space Gate" is different from AI to bi. In fact, the constant interference of the Reverend sister Sauce's Sunglasses party (see my avatar) makes the link very unstable. Reverend Sister's sunglasses. The party's interference is as follows: if there is a "time と gate" from Ai to Bi, then it is not possible to go back to AI from bi via some path and "Time と gate". So some areas may not reach, need to sail ocean to their own teleport can be.
Sail Ocean now stay in the S town, because he needs to put each "れいじまいご ベクトル becomes change" device adjustment completed, so Sail Ocean wrote a program calculation from S, for each region to calculate the minimum cost, if not possible, then output "Need teleport to Repair ”。 The final output, there are a total number of places that need to use teleport.
But because the dark sunglasses party constantly trouble, this procedure is now unable to work, please repeat out this program.
Input description Input Description
Line 1th has four spaces separated by integers t, R, p, and S.
The 2nd to R+1 row has 3 spaces separated by a positive integer that represents the AI, Bi, and CI of a road.
The r+2 to R+p+1 row has 3 spaces separated by a positive integer, representing an AI, Bi, and CI with a "time と space Gate".
Output Description Description
The 1th to T line output per line is the minimum cost of reaching the region I from S, if there is no output "Need teleport to Repair" (no quotes).
The last act of a total number of places is a need to use teleport.
Sample Input For example
6 3 3 4
1 2 5
3 4 5
5 6 10
3 5-100
4 6-100
1 3-10
Sample output Sample
Need Teleport to Repair
Need Teleport to Repair
5
0
-95
-100
2
Range of data and hints of the size & Hint
1≤t≤25000,1≤r≤50000,1≤p≤50000,1≤s≤t
1≤ai≤t,1≤bi≤t,-10000≤ci≤10000 (for "Time と space gate" costs may be negative)
Say Han ... Just looked at other students of the blog, feel they write good intentions ah qaq, but their lazy to no, do not want to write blog ... After two days to Beijing have time to do this time to do a good job of the problem to tidy up ...
In fact, under the tle there is another wa ... Because I also thought that does not have to export oneself to own distance, also did not take a good look at the example to turn over ... mdzz ...
The first tle is bare SPFA, the second is a manual read, the third is manually read into the +SPFA SLF optimization, this speed is simply hanging flying up ...
This problem is not the difficulty of thinking, without manual read SPFA optimization can be passed, this incredibly is a master problem ... Afraid.
The code is as follows:
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <
Queue> using namespace std;
const int MAX_V=25000+10;
const int MAX_E=100000+10;
int tot;
int first[max_v],nxt[max_e<<1],d[max_v]; struct edge{int from,to,cost;}
es[max_e<<1];
void read (int &a) {a=0;
int h=1;
Char C=getchar (); while (c< ' 0 ' | |
C> ' 9 ') {if (c== '-') h=-1;
C=getchar ();
while (c>= ' 0 ' &&c<= ' 9 ') {a*=10;
a+=c-' 0 ';
C=getchar ();
} a*=h;
} void Init () {memset (first,-1,sizeof (a));
Memset (d,0x3f,sizeof (d));
tot=0;
} void Build (int ff,int tt,int dd) {es[++tot]= (edge) {FF,TT,DD};
NXT[TOT]=FIRST[FF];
First[ff]=tot;
} bool Vis[max_v];
deque<int>q;
void SPFA (int s) {d[s]=0;
Vis[s]=1;
Q.push_front (s);
while (!q.empty ()) {int U=q.front ();
Q.pop_front ();
vis[u]=0; for (int i=first[u];i!=-1;i=nxt[i]) {int v=es[i].to;
if (d[v]>d[u]+es[i].cost) {d[v]=d[u]+es[i].cost;
if (!vis[v]) {vis[v]=1;
if (Q.empty ()) Q.push_front (v);
else if (D[v]>d[q.front ()]) Q.push_back (v);
else Q.push_front (v);
int main () {init ()}}}}
int v,e,pe,ts;
Read (V), read (E), read (Pe), read (Ts);
for (int i=1;i<=e;i++) {int ff,tt,dd;
Read (FF), read (TT), read (DD);
Build (FF,TT,DD);
Build (TT,FF,DD);
for (int i=1;i<=pe;i++) {int ff,tt,dd;
Read (FF), read (TT), read (DD);
Build (FF,TT,DD);
int cnt=0;
SPFA (Ts); for (int i=1;i<=v;i++) {if (d[i]==0x3f3f3f3f) {puts ("Need teleport to Repair");
cnt++;
else printf ("%d\n", D[i]);
printf ("%d\n", CNT);
return 0; }