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

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



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

代碼:

#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 閱讀(492) 評論(0)  編輯 收藏 引用 所屬分類: 圖論

只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            午夜精品福利一区二区蜜股av| 欧美成人亚洲成人| 亚洲美女av网站| 欧美人成在线视频| 99视频精品| 一区二区动漫| 国产精品日韩二区| 久久久久久免费| 久久亚洲精选| av不卡免费看| 亚洲欧美文学| 亚洲电影自拍| 日韩视频免费在线观看| 国产精品男女猛烈高潮激情| 久久久久久久999精品视频| 久久精品夜夜夜夜久久| 91久久综合| 夜夜夜久久久| 国产一区二区三区四区五区美女| 美女脱光内衣内裤视频久久网站| 美女网站久久| 亚洲曰本av电影| 性做久久久久久| 91久久精品国产91久久性色tv| 亚洲精品中文在线| 国产日韩一区二区三区在线播放| 免费在线观看成人av| 欧美日本一道本在线视频| 香蕉乱码成人久久天堂爱免费| 久久精品视频亚洲| 一区二区欧美视频| 久久国产成人| 亚洲在线黄色| 久久综合中文字幕| 午夜在线观看欧美| 欧美电影在线观看| 欧美在线日韩精品| 欧美精品一区二区三区很污很色的| 亚洲欧美一区二区激情| 免费亚洲电影在线观看| 欧美亚洲网站| 欧美国产欧美亚洲国产日韩mv天天看完整 | 卡一卡二国产精品| 欧美视频一区在线| 亚洲高清精品中出| 国产深夜精品福利| 亚洲视频精选在线| 亚洲精品午夜精品| 久久久久综合网| 午夜精品久久久久久久男人的天堂| 美女脱光内衣内裤视频久久网站| 欧美一级精品大片| 欧美日韩一区二区三区四区在线观看| 欧美在线综合视频| 欧美视频亚洲视频| 亚洲欧洲在线视频| 亚洲欧洲日产国产综合网| 欧美一级黄色网| 香蕉久久夜色精品国产使用方法| 欧美日韩国产区一| 亚洲精品视频中文字幕| 亚洲日本一区二区| 免费不卡在线观看| 欧美 日韩 国产一区二区在线视频| 国产婷婷一区二区| 亚洲欧美一区二区三区久久 | 国产精品资源在线观看| 99精品99久久久久久宅男| 日韩午夜在线| 欧美精品免费播放| 亚洲精品一区中文| 免费成人av在线| 久久亚洲一区二区| 国产精品在线看| 在线亚洲观看| 欧美一区二区三区精品电影| 欧美日韩精品一区二区| 亚洲靠逼com| 99热这里只有成人精品国产| 欧美日韩喷水| 亚洲一区二区精品在线| 欧美一区91| 激情av一区二区| 欧美成人dvd在线视频| 最新国产の精品合集bt伙计| 一区二区三区欧美在线| 欧美日韩亚洲一区二区三区| 91久久夜色精品国产九色| 亚洲免费电影在线观看| 国产精品va在线播放我和闺蜜| 亚洲视频在线观看网站| 欧美一区二区高清在线观看| 一区二区三区三区在线| 国产精品福利久久久| 亚洲一区欧美| 免费观看亚洲视频大全| 最新国产成人在线观看| 欧美日韩精品在线| 午夜精品一区二区三区四区| 麻豆成人综合网| 日韩五码在线| 国产农村妇女毛片精品久久麻豆| 欧美一区二区三区视频| 亚洲高清一二三区| 亚洲欧美欧美一区二区三区| 伊人久久大香线| 欧美日韩国产小视频| 小处雏高清一区二区三区| 欧美激情日韩| 亚洲欧美日韩成人| 亚洲国产成人精品久久| 国产精品久久久久毛片软件| 久久午夜视频| 亚洲尤物影院| 亚洲伦理中文字幕| 另类激情亚洲| 新67194成人永久网站| 亚洲激情综合| 国内精品久久久久国产盗摄免费观看完整版| 老司机精品视频网站| 亚洲欧美日韩第一区| 91久久精品一区| 欧美 日韩 国产 一区| 欧美一区午夜精品| 日韩视频中文字幕| 永久555www成人免费| 国产精品一区毛片| 欧美日韩综合在线免费观看| 嫩草成人www欧美| 久久久久久免费| 欧美亚洲在线观看| 亚洲香蕉伊综合在人在线视看| 亚洲国产视频直播| 欧美成人a视频| 久久久噜噜噜久久人人看| 午夜免费电影一区在线观看| 亚洲视频在线观看免费| 日韩视频一区二区三区在线播放| 精品69视频一区二区三区| 国产欧美日韩免费| 国产精品美女久久久久av超清| 欧美日韩岛国| 欧美精品国产一区| 免费在线亚洲| 欧美成人一区在线| 欧美a级片网| 欧美福利一区二区三区| 免费人成网站在线观看欧美高清 | 亚洲无线视频| 一区二区三区日韩欧美| 夜夜爽www精品| 夜夜夜久久久| 亚洲一区欧美激情| 午夜精品亚洲| 欧美一级淫片播放口| 久久9热精品视频| 久久精品夜色噜噜亚洲a∨| 久久精品伊人| 乱人伦精品视频在线观看| 男同欧美伦乱| 亚洲精品免费一二三区| 亚洲靠逼com| 亚洲欧美美女| 久久久久久一区| 欧美www视频| 欧美性jizz18性欧美| 国产精品久久亚洲7777| 国产一区免费视频| 亚洲精品1区| 亚洲性视频h| 久久人人精品| 亚洲国产欧美在线| 亚洲五月婷婷| 久久久久久尹人网香蕉| 欧美激情一区在线| 国产精品中文字幕在线观看| 激情成人av| 中国亚洲黄色| 久久尤物电影视频在线观看| 亚洲韩国青草视频| 亚洲一级一区| 麻豆9191精品国产| 国产精品捆绑调教| 在线国产精品一区| 亚洲综合三区| 欧美mv日韩mv亚洲| 中国成人黄色视屏| 老司机一区二区三区| 国产精品久久午夜| 亚洲精品免费电影| 久久精品国产999大香线蕉| 亚洲国产导航| 香港成人在线视频| 欧美日韩国产一区二区三区| 伊人一区二区三区久久精品| 9色精品在线| 欧美国产91| 欧美一区二视频| 欧美小视频在线| 99精品久久|