UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#189230#3321. 飞翔(fly)gaojieming100918ms13096kbC++112.0kb2023-10-04 09:18:072023-10-04 13:05:12

answer

#include<bits/stdc++.h>
#define ll long long
#define il inline
#define pn putchar('\n')
#define maxint 2147483647
#define min(x,y) (x<y?x:y)
#define max(x,y) (x>y?x:y)
#define maxn 505
#define maxm 125005
#define int ll
using namespace std;
struct Gragh
{
    int v,w,nex;
}e[maxm<<1];
struct Dijk
{
    int u,w;
    il bool operator < (const Dijk t) const {return w>t.w;} 
};
int n,m,top;
bool vis[maxn];
int c[maxn],dis[maxn],f[maxn][maxn],g[maxn][maxn],tf[maxn][maxn];
priority_queue<Dijk>q;
il void build_gra(int u,int v,int w)
{
    e[++top]=(Gragh){v,w,c[u]},c[u]=top;
}
il void dijkstra(int pos)
{
    memset(dis,0x3f,sizeof dis);
    dis[pos]=0;
    q.push((Dijk){pos,0});
    while(q.size())
    {
        Dijk t=q.top();q.pop();
        if(vis[t.u])continue;
        vis[t.u]=1;
        for(int i=c[t.u];i;i=e[i].nex)
            if(dis[t.u]+e[i].w<dis[e[i].v])
                dis[e[i].v]=dis[t.u]+e[i].w,q.push({e[i].v,dis[e[i].v]});
    }
}
signed main()
{
    #ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    #endif
    scanf("%lld%lld",&n,&m);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            f[i][j]=g[i][j]=tf[i][j]=1e9;
    while(m--)
    {
        int u,v,w;
        scanf("%lld%lld%lld",&u,&v,&w);
        f[u][v]=f[v][u]=1;
        g[u][v]=g[v][u]=min(g[u][v],w);
    }
    for(int i=1;i<=n;i++)
        f[i][i]=0;
    for(int k=1;k<=n;k++)
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
                f[i][j]=min(f[i][j],f[i][k]+f[k][j]);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            if(g[i][j]!=1e9)
                for(int k=1;k<=n;k++)
                    if(f[j][k]!=1e9)
                        tf[i][k]=min(tf[i][k],g[i][j]*(f[j][k]+1));
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            if(tf[i][j]!=1e9)
                build_gra(i,j,tf[i][j]);
    dijkstra(1);
    printf("%lld",dis[n]);
    return 0;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 1496kb

input:

20 40
1 2 690537
1 3 798286
2 4 984879
1 5 908148
3 6 891923
2 7 987330
5 8 978098
8 9 965037
8 10 6...

output:

807192

result:

ok single line: '807192'

Test #2:

score: 10
Accepted
time: 0ms
memory: 1500kb

input:

20 40
1 2 862239
2 3 697878
2 4 905713
1 5 710051
2 6 797312
2 7 702054
7 8 884083
7 9 786004
7 10 9...

output:

2373055

result:

ok single line: '2373055'

Test #3:

score: 10
Accepted
time: 0ms
memory: 1500kb

input:

20 40
1 2 876614
1 3 968907
3 4 860017
3 5 867995
5 6 713757
6 7 684056
4 8 928248
5 9 775400
7 10 8...

output:

1657179

result:

ok single line: '1657179'

Test #4:

score: 10
Accepted
time: 138ms
memory: 13060kb

input:

500 10000
1 2 1
1 3 1
3 4 1
1 5 1
4 6 1
3 7 1
6 8 1
8 9 1
9 10 1
9 11 1
9 12 1
11 13 1
9 14 1
14 15 ...

output:

2

result:

ok single line: '2'

Test #5:

score: 10
Accepted
time: 133ms
memory: 13064kb

input:

500 10000
1 2 1
2 3 1
3 4 1
1 5 1
4 6 1
6 7 1
6 8 1
8 9 1
8 10 1
10 11 1
7 12 1
8 13 1
13 14 1
12 15...

output:

2

result:

ok single line: '2'

Test #6:

score: 10
Accepted
time: 119ms
memory: 13096kb

input:

500 1000
1 2 923284
1 3 807610
1 4 869360
4 5 911570
2 6 733380
2 7 686639
6 8 704538
4 9 769480
7 1...

output:

4010302

result:

ok single line: '4010302'

Test #7:

score: 10
Accepted
time: 126ms
memory: 13080kb

input:

500 1000
1 2 947043
2 3 806915
3 4 670021
1 5 939043
2 6 788696
6 7 670515
3 8 889488
5 9 925621
8 1...

output:

4135596

result:

ok single line: '4135596'

Test #8:

score: 10
Accepted
time: 129ms
memory: 13096kb

input:

500 1000
1 2 940294
1 3 724108
3 4 774175
2 5 749134
3 6 814752
5 7 695034
5 8 968937
5 9 785345
7 1...

output:

5633972

result:

ok single line: '5633972'

Test #9:

score: 10
Accepted
time: 135ms
memory: 13072kb

input:

500 10000
1 2 876406
2 3 883210
2 4 818771
4 5 871755
3 6 709535
3 7 858204
7 8 732881
5 9 846857
8 ...

output:

1348166

result:

ok single line: '1348166'

Test #10:

score: 10
Accepted
time: 138ms
memory: 13072kb

input:

500 10000
1 2 777746
1 3 879140
3 4 813644
4 5 815532
5 6 951477
5 7 960811
5 8 727228
8 9 920934
6 ...

output:

1481760

result:

ok single line: '1481760'

Extra Test:

score: 0
Extra Test Passed