青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

posts - 7,comments - 3,trackbacks - 0
Sightseeing
Time Limit: 2000MSMemory Limit: 65536K
Total Submissions: 4917Accepted: 1688

Description

Tour operator Your Personal Holiday organises guided bus trips across the Benelux. Every day the bus moves from one city S to another city F. On this way, the tourists in the bus can see the sights alongside the route travelled. Moreover, the bus makes a number of stops (zero or more) at some beautiful cities, where the tourists get out to see the local sights.

Different groups of tourists may have different preferences for the sights they want to see, and thus for the route to be taken from S to F. Therefore, Your Personal Holiday wants to offer its clients a choice from many different routes. As hotels have been booked in advance, the starting city S and the final city F, though, are fixed. Two routes from S to F are considered different if there is at least one road from a city A to a city B which is part of one route, but not of the other route.

There is a restriction on the routes that the tourists may choose from. To leave enough time for the sightseeing at the stops (and to avoid using too much fuel), the bus has to take a short route from S to F. It has to be either a route with minimal distance, or a route which is one distance unit longer than the minimal distance. Indeed, by allowing routes that are one distance unit longer, the tourists may have more choice than by restricting them to exactly the minimal routes. This enhances the impression of a personal holiday.

For example, for the above road map, there are two minimal routes from S = 1 to F = 5: 1 → 2 → 5 and 1 → 3 → 5, both of length 6. There is one route that is one distance unit longer: 1 → 3 → 4 → 5, of length 7.

Now, given a (partial) road map of the Benelux and two cities S and F, tour operator Your Personal Holiday likes to know how many different routes it can offer to its clients, under the above restriction on the route length.

Input

The first line of the input file contains a single number: the number of test cases to follow. Each test case has the following format:

  • One line with two integers N and M, separated by a single space, with 2 ≤ N ≤ 1,000 and 1 ≤ M ≤ 10, 000: the number of cities and the number of roads in the road map.

  • M lines, each with three integers AB and L, separated by single spaces, with 1 ≤ AB ≤ NA ≠ B and 1 ≤ L ≤ 1,000, describing a road from city A to city B with length L.

    The roads are unidirectional. Hence, if there is a road from A to B, then there is not necessarily also a road from B to A. There may be different roads from a city A to a city B.

  • One line with two integers S and F, separated by a single space, with 1 ≤ SF ≤ N and S ≠ F: the starting city and the final city of the route.

    There will be at least one route from S to F.

Output

For every test case in the input file, the output should contain a single number, on a single line: the number of routes of minimal length or one distance unit longer. Test cases are such, that this number is at most 109 = 1,000,000,000.

Sample Input

2
5 8
1 2 3
1 3 2
1 4 5
2 3 1
2 5 3
3 4 2
3 5 4
4 5 3
1 5
5 6
2 3 1
3 2 1
3 1 10
4 5 2
5 2 7
5 2 7
4 1

Sample Output

3
2

Hint

The first test case above corresponds to the picture in the problem description.

Source



思路:
依據(jù)描寫可知,本題的要求即便要求出最短路和比最短路長1的次短路,因而可用Dijkstra來處理。翔實(shí)做法如下:用兩組數(shù)離別登記最短路和次短路的長度(dist),條數(shù)(cnt),拜會(huì)符號(hào)(used),建一個(gè)優(yōu)先隊(duì)列,元素單位包括節(jié)點(diǎn)序號(hào)(v),該節(jié)點(diǎn)路經(jīng)長(len),以及登記路徑種類(ref),每次從優(yōu)先隊(duì)列中取出管用節(jié)點(diǎn)后,用它所登記的路徑長更新待比擬路徑,離別用它和目前所登記的該節(jié)點(diǎn)的最短路徑以及此段路徑比擬,中意更新條件則登記路徑種類,并生成新節(jié)點(diǎn)加入優(yōu)先隊(duì)列,同時(shí)更新目前節(jié)點(diǎn)處該種類路徑條數(shù)。萬一不中意條件然而中意混同聯(lián)系,則增加相應(yīng)的條數(shù)到該節(jié)點(diǎn)所登記的路徑條數(shù)上。

代碼:

#include <cstdio>
#include 
<memory.h>
#include 
<queue>
#define N 1001
#define M 10001
#define INF 0x7fffffff
#define clr(a) memset(a, 0, sizeof(a))
using namespace std;

struct Edge
{
    
int v, len, ref;
    Edge 
*link;
    Edge new_E(
int v1, int l, int r)
    {
        v 
= v1, len = l, ref = r;
        
return *this;
    }
*E[N], mempool[M];

int dist[N][2], used[N][2], cnt[N][2];
int n, m, memh, S, T;

void AddEdge(int u, int v, int len)
{
    Edge 
*= &mempool[memh++];
    e 
-> v = v;
    e 
-> len = len;
    e 
-> link = E[u];
    E[u] 
= e;
}

bool operator < (Edge a, Edge b)
{
    
return a.len > b.len;
}

priority_queue 
<Edge, vector <Edge> > Q;

void InitData()
{
    
int i, u, v, len;
    memh 
= 0;
    scanf(
"%d%d"&n, &m);
    clr(E);
    
for (i = 1; i <= m; ++i)
    {
        scanf(
"%d%d%d"&u, &v, &len);
        AddEdge(u, v, len);
    }
    scanf(
"%d%d"&S, &T);
}

int Dijstra()
{
    Edge D, P;
    clr(cnt);
    clr(used);
    
for (int i = 1; i <= n; ++i)
        dist[i][
0= dist[i][1= INF;
    dist[S][
0= 0;
    cnt[S][
0= 1;
    
while (!Q.empty())
        Q.pop();
    Q.push(D.new_E(S, 
00));
    
while (!Q.empty())
    {
        P 
= Q.top();
        Q.pop();
        
if (!used[P.v][P.ref])
        {
            used[P.v][P.
ref= 1;
            
for (Edge *= E[P.v]; e; e = e -> link)
            {
                
int tmp = P.len + e -> len;
                
if (tmp < dist[e -> v][0])
                {
                    
if (dist[e -> v][0!= INF)
                    {
                        dist[e 
-> v][1= dist[e -> v][0];
                        cnt[e 
-> v][1= cnt[e -> v][0];
                        Q.push(D.new_E(e 
-> v, dist[e -> v][0], 1));
                    }
                    dist[e 
-> v][0= tmp;
                    cnt[e 
-> v][0= cnt[P.v][P.ref];
                    Q.push(D.new_E(e 
-> v, tmp, 0));
                }
                
else
                
if (tmp == dist[e -> v][0])
                {
                    cnt[e 
-> v][0+= cnt[P.v][P.ref];
                }
                
else
                
if (tmp < dist[e -> v][1])
                {
                    dist[e 
-> v][1= tmp;
                    cnt[e 
-> v][1= cnt[P.v][P.ref];
                    Q.push(D.new_E(e 
-> v, tmp, 1));
                }
                
else
                
if (dist[e -> v][1== tmp)
                {
                    cnt[e 
-> v][1+= cnt[P.v][P.ref];
                }
            }
        }
    }
    
if (dist[T][1- 1 == dist[T][0])
        cnt[T][
0+= cnt[T][1];
    
return cnt[T][0];
}

int main()
{
    
int T;
    scanf(
"%d"&T);
    
while (T--)
    {
        InitData();
        printf(
"%d\n", Dijstra());
    }
}
posted on 2011-10-17 16:30 LLawliet 閱讀(484) 評(píng)論(0)  編輯 收藏 引用 所屬分類: 圖論
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            一本到高清视频免费精品| 久久久午夜视频| 欧美成人一区二区在线 | 亚洲精品久久久久久久久久久久久| 亚洲丰满在线| 久久久噜噜噜久久中文字免| 在线观看一区| 亚洲国产精品第一区二区三区 | 久久久久一区| 久热精品视频在线观看一区| 亚洲精品乱码久久久久久久久| 亚洲美女中文字幕| 国产欧美日韩精品丝袜高跟鞋 | 欧美成人r级一区二区三区| 欧美精品亚洲二区| 午夜一区二区三区不卡视频| 久久精品国产精品| 欧美日韩免费在线视频| 亚洲欧美在线高清| 久久久999精品| 一本不卡影院| 欧美一区二区三区在线| 日韩亚洲综合在线| 午夜免费久久久久| 日韩视频在线观看国产| 午夜在线a亚洲v天堂网2018| 亚洲精品九九| 欧美在线观看一区| 亚洲午夜日本在线观看| 久久综合国产精品| 午夜精品福利在线观看| 欧美成人精品不卡视频在线观看 | 国产一区二区三区成人欧美日韩在线观看| 免费日韩成人| 国产精品一区一区三区| 欧美激情va永久在线播放| 国产麻豆精品视频| 亚洲精品中文字幕有码专区| 亚洲国产精品一区制服丝袜| 亚洲免费影院| 一区二区欧美激情| 老色鬼精品视频在线观看播放| 欧美在线亚洲一区| 国产精品magnet| 亚洲日本一区二区三区| 亚洲大胆美女视频| 欧美在线观看视频| 欧美专区在线| 国产精品视频免费观看| 一本一本久久| 亚洲网站在线| 欧美网站在线| 在线亚洲美日韩| 一二三区精品福利视频| 欧美成人69av| 亚洲国产婷婷综合在线精品| 亚洲国产欧美日韩另类综合| 久久久久久穴| 欧美成人按摩| 亚洲欧洲日韩在线| 免费日韩精品中文字幕视频在线| 久久一二三区| 尤物精品国产第一福利三区 | 一区二区三区欧美日韩| 亚洲天堂免费在线观看视频| 欧美精品久久99| 亚洲精品极品| 国产精品99久久久久久有的能看| 欧美日韩一区二区精品| 亚洲图片在区色| 午夜在线电影亚洲一区| 国产欧美日韩麻豆91| 欧美一二区视频| 久久午夜影视| 亚洲人在线视频| 欧美日韩精品综合在线| 99xxxx成人网| 欧美专区第一页| 在线观看成人av| 免费日韩成人| 一区二区三区精品久久久| 欧美亚洲一区二区在线| 激情成人av| 美女视频网站黄色亚洲| 亚洲精选中文字幕| 欧美中文字幕在线观看| 一区在线电影| 欧美日韩免费观看一区| 午夜久久久久久| 欧美激情视频网站| 亚洲视频在线观看免费| 国产自产v一区二区三区c| 麻豆91精品91久久久的内涵| 99re66热这里只有精品3直播| 欧美一区二区三区在线观看视频| 狠狠色香婷婷久久亚洲精品| 免费观看30秒视频久久| 一本色道久久综合亚洲精品高清| 久久久久一区| 亚洲性线免费观看视频成熟| 国产亚洲观看| 欧美日韩不卡| 久久精品一本久久99精品| 99国产精品国产精品久久| 久久久久久电影| 亚洲特黄一级片| 在线视频观看日韩| 国产精品理论片| 裸体一区二区| 欧美一区二区视频在线观看| 亚洲精品欧美专区| 欧美成在线观看| 欧美资源在线| 亚洲男人av电影| 亚洲国产一区二区三区青草影视| 国产精品永久| 欧美人与禽猛交乱配视频| 欧美在线你懂的| 亚洲午夜激情网站| 日韩午夜中文字幕| 欧美成人a∨高清免费观看| 久久www成人_看片免费不卡| 亚洲校园激情| 亚洲精品久久久久久下一站| 1024亚洲| 一区在线免费| 国产日韩亚洲欧美综合| 国产精品久久国产愉拍| 欧美日韩国产不卡| 欧美成人激情视频| 美女性感视频久久久| 久久精品综合一区| 欧美亚洲在线视频| 午夜精品视频在线观看| 亚洲在线视频| 亚洲一区欧美二区| 亚洲一区中文| 亚洲视频一区二区在线观看| 99亚洲精品| 亚洲手机成人高清视频| 夜夜嗨av一区二区三区四季av| 亚洲精品乱码| 日韩视频免费在线| 一二三四社区欧美黄| 一区二区久久久久久| 亚洲网站视频| 亚洲小少妇裸体bbw| 亚洲欧美视频在线观看| 欧美亚洲综合在线| 久久精品中文字幕一区二区三区| 久久久久久91香蕉国产| 久久婷婷国产麻豆91天堂| 媚黑女一区二区| 欧美人与禽猛交乱配| 欧美日韩在线另类| 国产精品视频久久一区| 国产色综合网| 亚洲国产片色| 亚洲视频自拍偷拍| 欧美尤物巨大精品爽| 美国成人毛片| 亚洲国产精品va在线观看黑人 | 久久在线免费观看| 欧美α欧美αv大片| 亚洲人被黑人高潮完整版| 一本色道久久综合精品竹菊| 亚洲欧美日韩一区二区| 久久精品人人做人人爽电影蜜月 | 亚洲精品专区| 欧美一级视频免费在线观看| 久久综合99re88久久爱| 欧美日产国产成人免费图片| 国产精品影片在线观看| 亚洲国产导航| 午夜在线一区| 欧美国产视频一区二区| 正在播放亚洲| 免费成人毛片| 国产午夜亚洲精品羞羞网站 | 国内精品国产成人| 一本久道久久久| 久久久噜噜噜久久久| 最新69国产成人精品视频免费| 亚洲欧美日本精品| 欧美激情综合在线| 国产一区视频在线看| 一区二区三区欧美| 久久一区国产| 亚洲综合国产激情另类一区| 欧美成人久久| 国产一区91| 亚洲综合精品四区| 亚洲国产精品久久91精品| 欧美一级一区| 国产精品久久久久久久久久三级 | 久久国产精品亚洲77777| 亚洲蜜桃精久久久久久久| 久久全国免费视频| 国产私拍一区| 亚洲欧美电影在线观看|