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

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>
            亚洲第一中文字幕在线观看| 国产一区二区三区无遮挡| 亚洲激情偷拍| 免费国产一区二区| 久久免费99精品久久久久久| 亚洲大胆人体在线| 91久久精品视频| 欧美四级在线观看| 欧美一区二区国产| 久久成人亚洲| 91久久一区二区| 亚洲视频精选在线| 黑人巨大精品欧美一区二区小视频 | 欧美视频第二页| 欧美一区永久视频免费观看| 久久丁香综合五月国产三级网站| 曰本成人黄色| 99天天综合性| 国内精品一区二区| 亚洲国产一区在线| 国产精品女主播在线观看| 久久亚洲精品网站| 欧美另类69精品久久久久9999| 亚洲欧美综合国产精品一区| 久久精品日韩一区二区三区| 制服丝袜亚洲播放| 久久精品久久综合| 亚洲一区二区久久| 美女日韩在线中文字幕| 亚洲欧美激情视频在线观看一区二区三区| 亚洲欧美日韩一区在线观看| 最新成人在线| 欧美一区中文字幕| 亚洲综合成人在线| 另类尿喷潮videofree| 亚洲欧美日韩另类精品一区二区三区| 久久一区免费| 久久久国产午夜精品| 欧美日韩国产成人在线免费| 蜜桃精品一区二区三区 | 久久久久久久久久久一区| 亚洲美女诱惑| 久久蜜桃资源一区二区老牛| 欧美主播一区二区三区| 欧美日韩在线不卡一区| 欧美激情精品久久久久久蜜臀 | 国产欧美va欧美不卡在线| 亚洲国内自拍| 在线免费不卡视频| 久久疯狂做爰流白浆xx| 欧美一级专区| 国产精品欧美一区二区三区奶水| 亚洲老司机av| 亚洲精品在线观| 免费美女久久99| 免费人成精品欧美精品| 国产亚洲激情| 欧美一区二区视频在线观看2020 | 亚洲电影免费观看高清完整版在线观看 | 欧美成人精品福利| 欧美插天视频在线播放| 黄色一区三区| 久久久久国内| 蜜臀a∨国产成人精品| 国语对白精品一区二区| 欧美亚洲日本一区| 久久久之久亚州精品露出| 国产美女在线精品免费观看| 亚洲制服丝袜在线| 欧美在线亚洲一区| 国产三级欧美三级| 欧美一区二区三区精品电影| 久久精品最新地址| 韩国自拍一区| 欧美成va人片在线观看| 亚洲人成毛片在线播放女女| 99热精品在线观看| 欧美日韩一区二区在线| 在线视频欧美日韩精品| 欧美亚洲一区在线| 国内精品久久久久影院薰衣草| 午夜视频在线观看一区二区三区 | 一区二区三区欧美日韩| 国产精品第13页| 午夜精品婷婷| 欧美国产激情二区三区| 99国产精品99久久久久久| 欧美日韩亚洲一区在线观看| 亚洲免费影院| 免费亚洲一区二区| 99在线精品观看| 国产免费亚洲高清| 裸体歌舞表演一区二区| 亚洲久久一区二区| 久久国产免费| 日韩午夜黄色| 国产一区二区三区免费在线观看| 美女诱惑一区| 亚洲综合日韩在线| 欧美激情免费观看| 亚洲欧美影音先锋| 亚洲国产日韩欧美| 国产精品永久免费在线| 麻豆精品在线视频| 亚洲欧美三级在线| 亚洲人成网站色ww在线| 久久精品在这里| 亚洲午夜激情网页| 亚洲福利视频网站| 国产精品一区在线观看你懂的| 蜜桃av一区二区在线观看| 亚洲一区二区三| 亚洲国产91色在线| 久久久777| 亚洲欧美日韩精品久久| 亚洲国产日韩一区二区| 国模套图日韩精品一区二区| 国产精品久久久久久福利一牛影视| 久久夜色精品一区| 午夜久久久久久| 亚洲天堂成人在线观看| 亚洲欧洲一区二区在线播放| 噜噜噜躁狠狠躁狠狠精品视频 | 亚洲精品欧美在线| 永久免费视频成人| 国产综合久久| 国产日韩欧美不卡| 国产精品一区二区久激情瑜伽 | 午夜国产精品视频| 一区二区高清视频| 亚洲免费黄色| 日韩一区二区精品视频| 亚洲国产清纯| 亚洲国产导航| 亚洲国产欧美一区二区三区丁香婷| 免费看的黄色欧美网站| 久久综合九色综合网站| 久久国产精彩视频| 久久国产主播| 久久久久综合| 免费观看在线综合色| 欧美14一18处毛片| 欧美成人综合在线| 欧美激情免费在线| 亚洲欧洲在线播放| av成人免费在线观看| 一区二区三区日韩欧美| 一区二区国产在线观看| 亚洲私人影院| 欧美一区二区三区精品电影| 久久精品国产第一区二区三区| 久久精品人人做人人综合| 久久久久亚洲综合| 母乳一区在线观看| 欧美日韩国产精品一区| 国产精品毛片大码女人| 国产欧美日韩一区二区三区在线观看| 国产区在线观看成人精品| 韩国免费一区| 亚洲精品免费电影| 亚洲综合另类| 狼狼综合久久久久综合网| 欧美黄色小视频| 一区二区三区免费看| 欧美一区二区三区精品| 美女视频网站黄色亚洲| 欧美日韩一区二区三| 国产午夜精品全部视频播放| 亚洲大片av| 亚洲欧美国产高清| 每日更新成人在线视频| 亚洲肉体裸体xxxx137| 亚洲视频免费在线| 久久乐国产精品| 国产精品乱看| 亚洲国产视频直播| 亚洲综合另类| 亚洲大片在线观看| 亚洲欧美日韩视频二区| 欧美高清日韩| 红桃av永久久久| 亚洲一区二区影院| 欧美成人精品福利| 亚洲一区区二区| 欧美精选午夜久久久乱码6080| 国产区二精品视| 亚洲婷婷综合色高清在线 | 欧美一区在线直播| 91久久国产综合久久91精品网站| 亚洲一区二区三区激情| 欧美大片国产精品| 国产在线精品二区| 亚洲自拍偷拍网址| 最新国产拍偷乱拍精品| 久久久久9999亚洲精品| 国产乱码精品一区二区三区五月婷| 亚洲剧情一区二区| 女主播福利一区| 久久精品成人欧美大片古装| 国产精品亚发布|