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

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>
            国产精品欧美久久久久无广告| 亚洲视频一区二区| 亚洲作爱视频| 亚洲一区尤物| 国产精品综合| 欧美一区二区女人| 欧美风情在线观看| 亚洲婷婷免费| 久久亚洲色图| 免费一级欧美片在线播放| 亚洲欧美日本国产有色| 亚洲成人资源| 亚洲国产精品小视频| 久久久精品一品道一区| 免费成人高清| 亚洲天堂av图片| 欧美精品在线一区二区| 1024国产精品| 亚洲国产乱码最新视频| 亚洲人成网站在线播| 国产精品午夜国产小视频| 亚洲国产成人久久综合| 亚洲免费电影在线| 欧美性猛交99久久久久99按摩| 欧美在线免费观看视频| 久久久久国产精品麻豆ai换脸| 欧美一区二区视频网站| 亚洲天堂av图片| 亚洲高清视频在线观看| 亚洲天堂第二页| 在线播放国产一区中文字幕剧情欧美| 蜜臀av一级做a爰片久久| 亚洲欧美日韩精品综合在线观看| 久久精品99无色码中文字幕 | 欧美va天堂va视频va在线| 亚洲国产清纯| 久久综合五月天婷婷伊人| 亚洲精选成人| 亚洲看片网站| 亚洲视频在线免费观看| 日韩视频免费在线观看| 亚洲欧美日韩一区二区三区在线观看| 一区二区三区视频在线观看| 久久久爽爽爽美女图片| 久久大香伊蕉在人线观看热2| 久久久久一区二区| 免费在线成人| 久久精品国产亚洲5555| 一道本一区二区| 欧美成人黑人xx视频免费观看| 欧美日韩免费观看一区三区 | 欧美电影免费观看网站| 亚洲精品视频二区| 亚洲精品一区久久久久久| 欧美一区二区三区另类| 亚洲福利在线视频| 亚洲视频每日更新| 欧美精品麻豆| 亚洲看片网站| 亚洲国产欧美在线| 久久久精品国产一区二区三区| 欧美在线黄色| 久久久精品网| 亚洲娇小video精品| 欧美伊人久久久久久久久影院 | 久久免费视频观看| 亚洲高清在线观看一区| 快射av在线播放一区| 亚洲网站在线观看| 欧美性猛交xxxx免费看久久久| 日韩一级欧洲| 免费观看成人鲁鲁鲁鲁鲁视频 | 国产精品欧美风情| 一区二区国产精品| 这里只有精品电影| 亚洲国产岛国毛片在线| 亚洲精品极品| 亚洲人成网在线播放| 欧美综合二区| 91久久精品日日躁夜夜躁欧美 | 亚洲免费高清| 免费欧美电影| 国产精品乱人伦一区二区| 亚洲视频你懂的| 亚洲成色www久久网站| 欧美日韩亚洲三区| 亚洲国产精品久久久久秋霞蜜臀| 欧美成人性网| 亚洲丝袜av一区| 伊人久久综合| 99re热这里只有精品免费视频| 欧美一区二区视频观看视频| 男女精品网站| 欧美在线一二三区| 欧美高清视频| 一区二区三区精密机械公司| 狠狠久久亚洲欧美专区| 亚洲欧美在线一区二区| 久久人人97超碰人人澡爱香蕉| 欧美剧在线观看| 老司机午夜精品视频| 亚洲国产美女精品久久久久∴| 欧美中文字幕在线视频| 久久人人超碰| 国产精品高清在线| 正在播放欧美一区| 国产女人精品视频| 免费人成精品欧美精品| 在线观看欧美黄色| 久久九九热免费视频| 欧美成人国产一区二区| 国产一区自拍视频| 亚洲人午夜精品免费| 激情六月婷婷久久| 亚洲免费小视频| 久久免费观看视频| 激情亚洲网站| 国产精品视频福利| 最新高清无码专区| 麻豆国产精品va在线观看不卡| 国产精品久久99| 欧美国产第一页| 亚洲一品av免费观看| 欧美日韩一二三区| 一本色道久久加勒比88综合| 亚洲三级视频| 欧美精品三区| 亚洲国产精品日韩| 黄色av日韩| 亚洲国产日本| 欧美在线视频观看免费网站| 亚洲一区二区综合| 久久一区二区三区超碰国产精品| 午夜久久资源| 亚洲精品一区二区三| 久久国产免费看| 欧美一区二区三区婷婷月色| 亚洲国产天堂久久综合网| 午夜久久影院| 亚洲欧美国产另类| 日韩亚洲欧美高清| 久久久久国产精品午夜一区| 欧美尤物巨大精品爽| 欧美激情精品久久久久久变态| 99国产精品久久久| 美女久久网站| 欧美视频一区在线| 欧美va亚洲va香蕉在线| 国产精品伦一区| 久久精品国产综合精品| 亚洲国产精品悠悠久久琪琪| 性感少妇一区| 亚洲另类自拍| 狠狠操狠狠色综合网| 国产精品人人爽人人做我的可爱 | 欧美伊人久久| 国产精品久久久免费| 欧美一区二区三区视频在线| 欧美中文字幕视频| 亚洲图片激情小说| 免费一区二区三区| 久久九九99| 久久爱另类一区二区小说| 一区二区三区高清| 蜜臀av国产精品久久久久| 国产欧亚日韩视频| 亚洲国产视频直播| 在线成人性视频| 国产精品v日韩精品| 国内精品嫩模av私拍在线观看 | 欧美韩日亚洲| 国产精品免费网站在线观看| 国产精品裸体一区二区三区| 欧美日韩一区二区免费视频| 国产精品夜夜夜一区二区三区尤| 欧美激情在线观看| 欧美激情在线| 亚洲欧美日韩电影| 亚洲欧美日韩中文视频| 夜夜嗨一区二区| 欧美激情国产日韩| 亚洲国产精品成人精品 | 麻豆乱码国产一区二区三区| 久久亚洲欧美国产精品乐播| 国产精品日产欧美久久久久| 午夜精品av| 久久夜色精品国产欧美乱| 亚洲欧美日韩一区在线观看| 欧美伦理影院| 久久狠狠久久综合桃花| 欧美在线视频免费播放| 老司机精品导航| 欧美亚洲一区二区三区| 欧美国产日韩精品| 精品盗摄一区二区三区| 亚洲第一黄网| 久久午夜激情| 欧美一区二区视频在线观看2020 | 久久久久久噜噜噜久久久精品| 99精品视频免费观看视频|