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

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 閱讀(484) 評論(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>
            亚洲免费网址| 欧美日韩国产高清| 欧美日韩一区二区高清| 亚洲精选大片| 99在线视频精品| 国产精品你懂的| 久久成人久久爱| 久久久久久久久久久成人| 亚洲成人影音| 亚洲激情第一页| 欧美日韩dvd在线观看| 亚洲男女自偷自拍| 午夜精品在线视频| 亚洲国产精品va在线观看黑人| 亚洲高清av在线| 国产精品日韩欧美一区二区三区| 久久国产欧美日韩精品| 久久一区二区视频| 在线视频亚洲| 欧美在线亚洲一区| 亚洲每日在线| 欧美亚洲网站| 一区二区高清在线观看| 亚洲制服欧美中文字幕中文字幕| 狠狠色狠狠色综合日日五| 亚洲三级电影全部在线观看高清| 国产精品免费小视频| 欧美不卡视频一区发布| 国产精品久久999| 美女久久一区| 国产精品久久看| 欧美激情亚洲精品| 国产精品视频一二三| 欧美激情亚洲另类| 国产伦精品一区二区三区高清| 亚洲福利专区| 一区二区三区在线免费观看| 一区二区三区不卡视频在线观看 | 欧美精品一卡二卡| 欧美在线观看网址综合| 欧美国产日韩精品| 久久午夜av| 国产精品黄色在线观看| 欧美国产一区二区在线观看| 国产日韩精品久久| 日韩亚洲一区二区| 欧美片在线观看| 欧美成人午夜免费视在线看片 | 久久不射网站| 亚洲素人在线| 欧美国产三区| 美女在线一区二区| 国产伦精品一区二区三| 日韩一级二级三级| 亚洲精品在线看| 美女视频黄a大片欧美| 久久久久久亚洲精品杨幂换脸| 欧美日韩一级片在线观看| 欧美成人精品一区二区| 伊人春色精品| 久久不射电影网| 欧美一区二区三区视频| 欧美色图一区二区三区| 亚洲精品一区久久久久久| 亚洲国产精品一区二区尤物区 | 午夜久久久久| 欧美在线播放视频| 国产女人精品视频| 亚洲免费视频一区二区| 亚洲欧美视频在线观看| 国产精品久久久久久户外露出| 99视频日韩| 亚洲欧美日韩国产综合| 国产精品久久久久久久久久ktv| 一区二区三区黄色| 亚洲综合视频一区| 国产欧美欧美| 久久精品免费播放| 欧美福利视频一区| 在线观看国产精品淫| 男女精品视频| 日韩亚洲在线观看| 亚洲欧美日韩一区在线| 国产情人节一区| 久久久久女教师免费一区| 欧美激情bt| 亚洲男人的天堂在线观看| 国产日韩av高清| 久久综合免费视频影院| 亚洲精品乱码久久久久久蜜桃麻豆 | 黄色另类av| 欧美肥婆bbw| 一区二区欧美日韩视频| 久久久亚洲国产天美传媒修理工| 尤物九九久久国产精品的分类| 欧美电影在线观看完整版| 一区二区三区av| 久久这里有精品15一区二区三区| 国产精品美女诱惑| 久久久久www| 99在线精品视频| 另类春色校园亚洲| 国产精品99久久不卡二区| 国产女主播一区二区| 欧美大片免费看| 欧美一站二站| 亚洲精品视频在线| 久热国产精品| 亚洲一区二区三区四区中文| 在线电影一区| 欧美日韩一区二区三区高清| 亚洲婷婷在线| 美女亚洲精品| 欧美一区二区在线观看| 黑人巨大精品欧美一区二区| 欧美日本视频在线| 欧美亚洲视频一区二区| 麻豆精品91| 欧美一区二区福利在线| 99re6热只有精品免费观看| 国产在线精品二区| 欧美日韩a区| 久久在线观看视频| 在线一区二区三区四区| 欧美成人午夜剧场免费观看| 久久久久久黄| 久久精品亚洲精品| 亚洲免费视频成人| 亚洲精品永久免费| 亚洲国产欧美在线| 精品不卡一区二区三区| 国产一区二区欧美| 国产欧美69| 国产精品欧美久久| 欧美色偷偷大香| 欧美特黄一区| 欧美日韩国产bt| 欧美日韩视频一区二区| 你懂的成人av| 免费高清在线视频一区·| 久久久噜噜噜久久中文字幕色伊伊| 亚洲欧美色一区| 亚洲一区二区三区四区在线观看 | 亚洲男人的天堂在线aⅴ视频| 一区二区三区www| 一区二区欧美日韩视频| 一区二区国产日产| 欧美午夜片欧美片在线观看| 欧美精品色网| 欧美日韩久久久久久| 欧美日韩国产精品成人| 欧美精品日韩| 国产精品海角社区在线观看| 欧美日韩一区二区三区免费| 欧美午夜精品久久久久久浪潮| 欧美日韩美女一区二区| 欧美四级剧情无删版影片| 国产精品久久久久久妇女6080 | 女人天堂亚洲aⅴ在线观看| 久久一区精品| 欧美激情久久久久| 欧美国产高清| 欧美午夜精品久久久久久久| 国产人久久人人人人爽| 免费在线亚洲| 久久美女性网| 免费在线观看日韩欧美| 欧美精品九九| 国产精品a久久久久久| 国产精品中文字幕在线观看| 国产农村妇女精品一二区| 国产一区二区三区观看| 永久555www成人免费| 一区二区不卡在线视频 午夜欧美不卡在| 亚洲福利视频网站| 亚洲网址在线| 久久视频国产精品免费视频在线| 欧美激情一区二区| 在线亚洲激情| 久久永久免费| 欧美色网在线| 亚洲第一狼人社区| 亚洲午夜影视影院在线观看| 久久久av网站| 一区二区三区国产| 久久字幕精品一区| 欧美日韩国产成人在线观看| 国产亚洲成精品久久| 在线观看一区| 亚洲欧美另类久久久精品2019| 欧美成人一品| 亚洲永久在线| 欧美国产高潮xxxx1819| 国产精品久久久久免费a∨| 亚洲国产欧美国产综合一区| 欧美一区午夜精品| 亚洲乱码国产乱码精品精可以看 | 亚洲精品国久久99热| 久久国产精品黑丝| 国产精品无码永久免费888|