> 데이터 베이스 > MySQL 튜토리얼 > codeforces Round #241(div2) E解题报告

codeforces Round #241(div2) E解题报告

WBOY
풀어 주다: 2016-06-07 15:18:31
원래의
1360명이 탐색했습니다.

E. President's Path time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Good old Berland has n cities and m roads. Each road connects a pair of distinct cities and is bidirectional.

E. President's Path

time limit per test

4 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Good old Berland has n cities and m roads. Each road connects a pair of distinct cities and is bidirectional. Between any pair of cities, there is at most one road. For each road, we know its length.

We also know that the President will soon ride along the Berland roads from city s to city t. Naturally, he will choose one of the shortest paths from s to t, but nobody can say for sure which path he will choose.

The Minister for Transport is really afraid that the President might get upset by the state of the roads in the country. That is the reason he is planning to repair the roads in the possible President's path.

Making the budget for such an event is not an easy task. For all possible distinct pairs s,?t (s?t) find the number of roads that lie on at least one shortest path from s to t.

Input

The first line of the input contains integers n,?m (2?≤?n?≤?5000?≤?m?≤?n·(n?-?1)?/?2) — the number of cities and roads, correspondingly. Then m lines follow, containing the road descriptions, one description per line. Each description contains three integersxi,?yi,?li (1?≤?xi,?yi?≤?n,?xi?≠?yi,?1?≤?li?≤?106), where xi,?yi are the numbers of the cities connected by the i-th road and li is its length.

Output

Print the sequence of codeforces Round #241(div2) E解题报告 integers c12,?c13,?...,?c1n,?c23,?c24,?...,?c2n,?...,?cn?-?1,?n, where cst is the number of roads that can lie on the shortest path from s to t. Print the elements of sequence c in the described order. If the pair of cities s and t don't have a path between them, then cst?=?0.

Sample test(s)

input

5 6
1 2 1
2 3 1
3 4 1
4 1 1
2 4 2
4 5 4
로그인 후 복사

output

1 4 1 2 1 5 6 1 2 1 
로그인 후 복사

题目大意:

        给出一个图,要求求出每个点之间的最短距离的路总条数.


解法:

        由于需要求出每个点之间的最短距离的路总条数,我们可以将问题拆分为: 1.最短距离; 2.符合最短距离的路的总条数.

        对于问题1,可以用floyd算法可以算出来;

        对于问题2,本题的重点所在,要求出路的总条数,而且不能重复.不能重复的话,我们可以按照每个点来计算,且每个点,我们只计算点周围的最短路径的路的条数,这样就可以防止重复. 因为1条边不可能统计2次.(详见代码).

              

代码:

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>

using namespace std;

const int lim = 500000001;

class TMain {
    
    private:
        
        int n, m, f[505][505], dis[505][505], ans[505][505], now[505];
        
    public:
        
        int run() {
            scanf("%d %d", &n, &m);
            for (int i = 1; i <br>
<br>

<p><br>
</p>
<p><br>
</p>


</algorithm></iostream></cstdlib></cstdio>
로그인 후 복사
관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿