#include <bits/stdc++.h>
using namespace std;
typedef long long lo;
typedef pair< lo,lo > PII;
typedef pair< lo,PII > PIII;
typedef pair< lo,PIII > PIIII;
typedef pair< lo,PIIII > PIIIII;
typedef pair< lo,PIIIII > PIIIIII;
#define fi first
#define se second
#define mp make_pair
#define endl "\n"
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)
#define int long long
const lo inf = 1000000000000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 1005;
const lo mod = 1000000007;
int n,m,b[li],a[li],k,flag,t,val[li],vis[li],yasak,mn,ans1,ans2,cev,d[li];
string s;
vector<PIIII> v[li];
//~ inline void sp2(){
//~ priority_queue<PIIIII> pq;
//~ pq.push({0,{n,{0,{0,0}}}});
//~ FOR vis[i][0]=0;
//~ FOR vis[i][1]=0;
//~ mn=inf;
//~ while(pq.size()){
//~ int co=-pq.top().fi;
//~ int node=pq.top().se.fi;
//~ int hak=pq.top().se.se.fi;
//~ int xx=pq.top().se.se.se.fi;
//~ int yy=pq.top().se.se.se.se;
//~ pq.pop();
//~ if(vis[node][hak])continue;
//~ vis[node][hak]=1;
//~ if(node==1)mn=min(mn,co);
//~ for(int i=0;i<(int)v[node].size();i++){
//~ int go=v[node][i].fi;
//~ if(node==xx && go==yy)continue;
//~ if(v[node][i].se.se==0)pq.push({-co-v[node][i].se.fi,{go,{hak,{xx,yy}}}});
//~ else{
//~ if(hak)continue;
//~ pq.push({-co-v[node][i].se.fi,{go,{1,{go,node}}}});
//~ }
//~ }
//~ }
//~ }
//~ inline void sp3(int xxx,int yyy){
//~ priority_queue<PIIIII> pq;
//~ pq.push({0,{n,{1,{xxx,yyy}}}});
//~ FOR vis[i][0]=0;
//~ FOR vis[i][1]=0;
//~ mn=inf;
//~ while(pq.size()){
//~ int co=-pq.top().fi;
//~ int node=pq.top().se.fi;
//~ int hak=pq.top().se.se.fi;
//~ int xx=pq.top().se.se.se.fi;
//~ int yy=pq.top().se.se.se.se;
//~ pq.pop();
//~ if(vis[node][hak])continue;
//~ vis[node][hak]=1;
//~ if(node==1)mn=min(mn,co);
//~ cout<<xx<<" : : "<<yy<<endl;
//~ for(int i=0;i<(int)v[node].size();i++){
//~ int go=v[node][i].fi;
//~ if(node==xx && go==yy)continue;
//~ if(v[node][i].se.se==0)pq.push({-co-v[node][i].se.fi,{go,{hak,{xx,yy}}}});
//~ else{
//~ if(hak)continue;
//~ pq.push({-co-v[node][i].se.fi,{go,{1,{go,node}}}});
//~ }
//~ }
//~ }
//~ }
inline void sp(int ii){
priority_queue<PII> pq;
pq.push({0,ii});
FOR vis[i]=0;
ans1=-1;
ans2=-1;
while(pq.size()){
int co=-pq.top().fi;
int node=pq.top().se;
pq.pop();
if(vis[node])continue;
vis[node]=1;
if(node==1)ans1=co;
if(node==n)ans2=co;
for(int i=0;i<(int)v[node].size();i++){
if(v[node][i].se.se.se==yasak && v[node][i].se.se.fi==0)continue;
if(v[node][i].se.se.se!=yasak && v[node][i].se.se.fi==1)continue;
pq.push({-co-v[node][i].se.fi,v[node][i].fi});
}
}
}
main(void){
scanf("%lld %lld",&n,&m);
for(int i=1;i<=m;i++){
int x,y,z;
scanf("%lld %lld %lld %lld",&x,&y,&z,&d[i]);
v[x].pb({y,{z,{0,i}}});
v[y].pb({x,{z,{1,i}}});
}
int ans=inf;
for(int i=1;i<=m;i++){
yasak=i;
sp(1);
if(ans2==-1)continue;
cev=ans2;
sp(n);
if(ans1==-1)continue;
cev+=ans1;
cev+=d[i];
ans=min(ans,cev);
}
yasak=0;
sp(1);
if(ans2!=-1){
cev=ans2;
sp(n);
if(ans1!=-1){
cev+=ans1;
ans=min(ans,cev);
}
}
if(ans==inf)ans=-1;
printf("%lld\n",ans);
return 0;
}
Compilation message
ho_t4.cpp:112:10: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(void){
^
ho_t4.cpp: In function 'int main()':
ho_t4.cpp:113:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld",&n,&m);
~~~~~^~~~~~~~~~~~~~~~~~~
ho_t4.cpp:116:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld %lld %lld",&x,&y,&z,&d[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
177 ms |
504 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
213 ms |
512 KB |
Output is correct |
4 |
Correct |
211 ms |
512 KB |
Output is correct |
5 |
Correct |
214 ms |
512 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
185 ms |
516 KB |
Output is correct |
10 |
Correct |
222 ms |
632 KB |
Output is correct |
11 |
Correct |
215 ms |
512 KB |
Output is correct |
12 |
Correct |
212 ms |
512 KB |
Output is correct |
13 |
Correct |
79 ms |
632 KB |
Output is correct |
14 |
Correct |
142 ms |
512 KB |
Output is correct |
15 |
Correct |
35 ms |
512 KB |
Output is correct |
16 |
Correct |
143 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4 ms |
1280 KB |
Time limit exceeded (wall clock) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
183 ms |
508 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Execution timed out |
4 ms |
1280 KB |
Time limit exceeded (wall clock) |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
177 ms |
504 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
213 ms |
512 KB |
Output is correct |
4 |
Correct |
211 ms |
512 KB |
Output is correct |
5 |
Correct |
214 ms |
512 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
185 ms |
516 KB |
Output is correct |
10 |
Correct |
222 ms |
632 KB |
Output is correct |
11 |
Correct |
215 ms |
512 KB |
Output is correct |
12 |
Correct |
212 ms |
512 KB |
Output is correct |
13 |
Correct |
79 ms |
632 KB |
Output is correct |
14 |
Correct |
142 ms |
512 KB |
Output is correct |
15 |
Correct |
35 ms |
512 KB |
Output is correct |
16 |
Correct |
143 ms |
512 KB |
Output is correct |
17 |
Execution timed out |
4 ms |
1280 KB |
Time limit exceeded (wall clock) |
18 |
Halted |
0 ms |
0 KB |
- |