[2384] Luo Gu shortest

Topic background

Dog rotten brother do most short-circuit, suddenly a witty exam Bosh, Bosh did not expect the test Bosh live ... can you help solve it?

He will give you 10% 100000000000000000000000000000000000 gold w

Title Description

Given n points weighted directed graph, find the path from 1 to n of the product of the smallest edge weights of simple paths.

Input and output formats

Input formats:

 

The first line reads two integers n, m, m represents a total of n points edges. Next m lines of three positive integers x, y, z, represents the point x to point y as there is a right side edge of z.

 

Output formats:

 

The output includes only one line, denoted by the path of seeking the right side of the plot, because the answer may be large, so the dog brother graciously let you output it to analog remainder of 9987.

Of course, the number is a nonsense w

// Xie fyszzhouzj correction w

For 20% of the data, n <= 10.

To 100% of the data, n <= 1000, m <= 1000000. The right side is not more than 10,000.

 

Sample input and output

Input Sample # 1:  Copy
3 3
1 2 3 
2 3 3 
1 3 10
Output Sample # 1:  Copy
9

Explanation

Take a good look to write yo w

Solution: simple dijkstra on the way, the addition into multiplication.

(Wrong topic, directed graph undirected thought, hey for a long time)

#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
typedef long long ll;
using namespace std;
const int oo=2147483647;
const int mod=9987;
int n,m,dis[5005],vis[5005],a[5005][5005];
int main(){
    freopen("2384.in","r",stdin);
    freopen("2384.out","w",stdout);
    scanf("%d %d",&n,&m);
    int x,y,z;
    //memset(a,100000,sizeof(a));
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            a[i][j]=100000;
    for(int i=1;i<=m;i++){
        cin>>x>>y>>z;
        a[x][y]=z;
        //a[y][x]=z;
    }
    for(int i=1;i<=n;i++)
        dis[i]=a[1][i];
    dis[1]=0;
    vis[1]=1;
    for(int i=1;i<=n;i++){
        int now=oo,ii;
        for(int j=1;j<=n;j++)
            if(vis[j]==0 && dis[j]<now){
                ii=j; now=dis[j];
            }
        vis[ii]=1;
        for(int j=1;j<=n;j++)
            if(dis[ii]*a[ii][j]<dis[j])
               A [j] = A [ii] * and [ii] [j];
    }
    cout<<dis[n]%mod<<endl;
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/wuhu-JJJ/p/11141326.html