#include<bits/stdc++.h>
using namespace std;
#define int long long
const int inf=0x0f0f0f0f0f0f0f0f;
int n,m,g[210][210],h[210][210],f[210][210];
bool vis[210];
void Dijkstra(int S,int *dis,int *fa){
for(int i=0;i<=n;i++)dis[i]=inf,vis[i]=false;
dis[S]=0;
while(true){
int x=0;
for(int i=1;i<=n;i++)if(!vis[i]&&dis[i]<dis[x])x=i;
if(!x)break;
vis[x]=true;
for(int y=1;y<=n;y++)if(dis[y]>dis[x]+g[x][y])dis[y]=dis[x]+g[x][y],fa[y]=x;
}
// for(int i=1;i<=n;i++)printf("%d ",dis[i]);puts("");
}
int dis1[210],fa1[210],sid1[210],af1[210],disn[210],fan[210],sidn[210],afn[210],dist[210],fat[210];
int u[51000],v[51000],c[51000],d[51000];
int res=inf;
signed main(){
scanf("%lld%lld",&n,&m),memset(g,inf,sizeof(g)),memset(f,inf,sizeof(f));
for(int i=1;i<=m;i++){
scanf("%lld%lld%lld%lld",&u[i],&v[i],&c[i],&d[i]);
if(g[u[i]][v[i]]>=c[i])f[u[i]][v[i]]=g[u[i]][v[i]],g[u[i]][v[i]]=c[i];
else f[u[i]][v[i]]=min(f[u[i]][v[i]],c[i]);
}
// for(int i=1;i<=n;i++){for(int j=1;j<=n;j++)printf("%d ",g[i][j]);puts("");}
// for(int i=1;i<=n;i++){for(int j=1;j<=n;j++)printf("%d ",f[i][j]);puts("");}
Dijkstra(1,dis1,fa1),Dijkstra(n,disn,fan);
res=min(res,dis1[n]+disn[1]);
for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)h[i][j]=g[i][j];
for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)g[i][j]=h[j][i];
Dijkstra(1,sid1,af1),Dijkstra(n,sidn,afn);
for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)g[i][j]=h[i][j];
memcpy(h,g,sizeof(g));
for(int i=1;i<=m;i++){
int tmpa=g[u[i]][v[i]],tmpb=g[v[i]][u[i]];
g[u[i]][v[i]]=f[u[i]][v[i]];
g[v[i]][u[i]]=min(g[v[i]][u[i]],c[i]);
int p=0;
if(fa1[v[i]]!=u[i]||dis1[u[i]]+c[i]!=dis1[v[i]])p=min(dis1[n],dis1[v[i]]+c[i]+sidn[u[i]]);
else Dijkstra(1,dist,fat),p=dist[n];
int q=0;
if(fan[v[i]]!=u[i]||disn[u[i]]+c[i]!=disn[v[i]])q=min(disn[1],disn[v[i]]+c[i]+sid1[u[i]]);
else Dijkstra(n,dist,fat),q=dist[1];
g[u[i]][v[i]]=tmpa;
g[v[i]][u[i]]=tmpb;
res=min(res,p+q+d[i]);
}
printf("%lld\n",res==inf?-1:res);
return 0;
}
Compilation message
ho_t4.cpp: In function 'int main()':
ho_t4.cpp:23:35: warning: overflow in conversion from 'long long int' to 'int' changes value from '1085102592571150095' to '252645135' [-Woverflow]
23 | scanf("%lld%lld",&n,&m),memset(g,inf,sizeof(g)),memset(f,inf,sizeof(f));
| ^~~
ho_t4.cpp:23:59: warning: overflow in conversion from 'long long int' to 'int' changes value from '1085102592571150095' to '252645135' [-Woverflow]
23 | scanf("%lld%lld",&n,&m),memset(g,inf,sizeof(g)),memset(f,inf,sizeof(f));
| ^~~
ho_t4.cpp:23:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
23 | scanf("%lld%lld",&n,&m),memset(g,inf,sizeof(g)),memset(f,inf,sizeof(f));
| ~~~~~^~~~~~~~~~~~~~~~~~
ho_t4.cpp:25:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
25 | scanf("%lld%lld%lld%lld",&u[i],&v[i],&c[i],&d[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
1388 KB |
Output is correct |
2 |
Correct |
1 ms |
1388 KB |
Output is correct |
3 |
Correct |
59 ms |
1388 KB |
Output is correct |
4 |
Correct |
61 ms |
1536 KB |
Output is correct |
5 |
Correct |
2 ms |
1388 KB |
Output is correct |
6 |
Correct |
2 ms |
1516 KB |
Output is correct |
7 |
Correct |
2 ms |
1388 KB |
Output is correct |
8 |
Correct |
1 ms |
1388 KB |
Output is correct |
9 |
Correct |
2 ms |
1388 KB |
Output is correct |
10 |
Correct |
63 ms |
1516 KB |
Output is correct |
11 |
Correct |
60 ms |
1408 KB |
Output is correct |
12 |
Correct |
60 ms |
1516 KB |
Output is correct |
13 |
Correct |
17 ms |
1388 KB |
Output is correct |
14 |
Correct |
38 ms |
1388 KB |
Output is correct |
15 |
Correct |
37 ms |
1388 KB |
Output is correct |
16 |
Correct |
37 ms |
1388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
146 ms |
3948 KB |
Output is correct |
2 |
Correct |
145 ms |
4076 KB |
Output is correct |
3 |
Correct |
171 ms |
4076 KB |
Output is correct |
4 |
Correct |
119 ms |
1516 KB |
Output is correct |
5 |
Correct |
98 ms |
1388 KB |
Output is correct |
6 |
Correct |
2 ms |
1388 KB |
Output is correct |
7 |
Correct |
3 ms |
1388 KB |
Output is correct |
8 |
Correct |
1 ms |
1388 KB |
Output is correct |
9 |
Correct |
59 ms |
4096 KB |
Output is correct |
10 |
Correct |
61 ms |
4076 KB |
Output is correct |
11 |
Correct |
102 ms |
4204 KB |
Output is correct |
12 |
Correct |
99 ms |
4204 KB |
Output is correct |
13 |
Correct |
97 ms |
4076 KB |
Output is correct |
14 |
Correct |
89 ms |
4076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
1388 KB |
Output is correct |
2 |
Correct |
7 ms |
1388 KB |
Output is correct |
3 |
Correct |
113 ms |
3436 KB |
Output is correct |
4 |
Correct |
3 ms |
1516 KB |
Output is correct |
5 |
Correct |
130 ms |
3820 KB |
Output is correct |
6 |
Correct |
1 ms |
1388 KB |
Output is correct |
7 |
Correct |
1 ms |
1388 KB |
Output is correct |
8 |
Correct |
52 ms |
3820 KB |
Output is correct |
9 |
Correct |
59 ms |
3820 KB |
Output is correct |
10 |
Correct |
113 ms |
3820 KB |
Output is correct |
11 |
Correct |
111 ms |
3968 KB |
Output is correct |
12 |
Correct |
124 ms |
4076 KB |
Output is correct |
13 |
Correct |
1 ms |
1388 KB |
Output is correct |
14 |
Correct |
1 ms |
1388 KB |
Output is correct |
15 |
Correct |
1 ms |
1388 KB |
Output is correct |
16 |
Correct |
1 ms |
1388 KB |
Output is correct |
17 |
Correct |
1 ms |
1388 KB |
Output is correct |
18 |
Correct |
1 ms |
1388 KB |
Output is correct |
19 |
Correct |
112 ms |
3840 KB |
Output is correct |
20 |
Correct |
113 ms |
3940 KB |
Output is correct |
21 |
Correct |
110 ms |
3820 KB |
Output is correct |
22 |
Correct |
112 ms |
3948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
1388 KB |
Output is correct |
2 |
Correct |
1 ms |
1388 KB |
Output is correct |
3 |
Correct |
59 ms |
1388 KB |
Output is correct |
4 |
Correct |
61 ms |
1536 KB |
Output is correct |
5 |
Correct |
2 ms |
1388 KB |
Output is correct |
6 |
Correct |
2 ms |
1516 KB |
Output is correct |
7 |
Correct |
2 ms |
1388 KB |
Output is correct |
8 |
Correct |
1 ms |
1388 KB |
Output is correct |
9 |
Correct |
2 ms |
1388 KB |
Output is correct |
10 |
Correct |
63 ms |
1516 KB |
Output is correct |
11 |
Correct |
60 ms |
1408 KB |
Output is correct |
12 |
Correct |
60 ms |
1516 KB |
Output is correct |
13 |
Correct |
17 ms |
1388 KB |
Output is correct |
14 |
Correct |
38 ms |
1388 KB |
Output is correct |
15 |
Correct |
37 ms |
1388 KB |
Output is correct |
16 |
Correct |
37 ms |
1388 KB |
Output is correct |
17 |
Correct |
146 ms |
3948 KB |
Output is correct |
18 |
Correct |
145 ms |
4076 KB |
Output is correct |
19 |
Correct |
171 ms |
4076 KB |
Output is correct |
20 |
Correct |
119 ms |
1516 KB |
Output is correct |
21 |
Correct |
98 ms |
1388 KB |
Output is correct |
22 |
Correct |
2 ms |
1388 KB |
Output is correct |
23 |
Correct |
3 ms |
1388 KB |
Output is correct |
24 |
Correct |
1 ms |
1388 KB |
Output is correct |
25 |
Correct |
59 ms |
4096 KB |
Output is correct |
26 |
Correct |
61 ms |
4076 KB |
Output is correct |
27 |
Correct |
102 ms |
4204 KB |
Output is correct |
28 |
Correct |
99 ms |
4204 KB |
Output is correct |
29 |
Correct |
97 ms |
4076 KB |
Output is correct |
30 |
Correct |
89 ms |
4076 KB |
Output is correct |
31 |
Correct |
56 ms |
1388 KB |
Output is correct |
32 |
Correct |
7 ms |
1388 KB |
Output is correct |
33 |
Correct |
113 ms |
3436 KB |
Output is correct |
34 |
Correct |
3 ms |
1516 KB |
Output is correct |
35 |
Correct |
130 ms |
3820 KB |
Output is correct |
36 |
Correct |
1 ms |
1388 KB |
Output is correct |
37 |
Correct |
1 ms |
1388 KB |
Output is correct |
38 |
Correct |
52 ms |
3820 KB |
Output is correct |
39 |
Correct |
59 ms |
3820 KB |
Output is correct |
40 |
Correct |
113 ms |
3820 KB |
Output is correct |
41 |
Correct |
111 ms |
3968 KB |
Output is correct |
42 |
Correct |
124 ms |
4076 KB |
Output is correct |
43 |
Correct |
1 ms |
1388 KB |
Output is correct |
44 |
Correct |
1 ms |
1388 KB |
Output is correct |
45 |
Correct |
1 ms |
1388 KB |
Output is correct |
46 |
Correct |
1 ms |
1388 KB |
Output is correct |
47 |
Correct |
1 ms |
1388 KB |
Output is correct |
48 |
Correct |
1 ms |
1388 KB |
Output is correct |
49 |
Correct |
112 ms |
3840 KB |
Output is correct |
50 |
Correct |
113 ms |
3940 KB |
Output is correct |
51 |
Correct |
110 ms |
3820 KB |
Output is correct |
52 |
Correct |
112 ms |
3948 KB |
Output is correct |
53 |
Correct |
83 ms |
4076 KB |
Output is correct |
54 |
Correct |
83 ms |
3948 KB |
Output is correct |
55 |
Correct |
86 ms |
3948 KB |
Output is correct |
56 |
Correct |
59 ms |
1388 KB |
Output is correct |
57 |
Correct |
61 ms |
1388 KB |
Output is correct |
58 |
Correct |
80 ms |
3436 KB |
Output is correct |
59 |
Correct |
81 ms |
3520 KB |
Output is correct |
60 |
Correct |
82 ms |
3436 KB |
Output is correct |
61 |
Correct |
79 ms |
3436 KB |
Output is correct |
62 |
Correct |
79 ms |
3436 KB |
Output is correct |
63 |
Correct |
82 ms |
3436 KB |
Output is correct |
64 |
Correct |
96 ms |
3564 KB |
Output is correct |
65 |
Correct |
84 ms |
3436 KB |
Output is correct |
66 |
Correct |
79 ms |
3436 KB |
Output is correct |
67 |
Correct |
16 ms |
3436 KB |
Output is correct |
68 |
Correct |
40 ms |
4076 KB |
Output is correct |
69 |
Correct |
38 ms |
4076 KB |
Output is correct |
70 |
Correct |
62 ms |
4076 KB |
Output is correct |
71 |
Correct |
60 ms |
4076 KB |
Output is correct |
72 |
Correct |
63 ms |
4076 KB |
Output is correct |
73 |
Correct |
64 ms |
4076 KB |
Output is correct |
74 |
Correct |
60 ms |
4076 KB |
Output is correct |