#include <bits/stdc++.h>
#define tt cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0)
#define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define db long double
#define sz(a) ((int)(a).size())
#define pb emplace_back
#define pf emplace_front
#define pob pop_back
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define ins emplace
#define mp make_pair
using namespace std;
const int MOD = 1e9+7, MAXN = 5e4+5;
const string NAME = "";
struct Edge{
int to,weight,pos;
bool dir;
Edge(int a, int b, int c, bool d){
to=a, weight=b, pos=c, dir=d;
}
};
int n,m;
ll rs=1e18,dist1[205],distN[205];
bool cur[MAXN];
vector<Edge> adj[205];
void dijkstra(int u, ll dist[]){
priority_queue<pair<ll,int>, vector<pair<ll,int>>, greater<pair<ll,int>>> pq;
dist[u]=0, pq.ins(0,u);
while(!pq.empty()){
pair<ll,int> top = pq.top();
pq.pop();
if(top.fi>dist[top.se]) continue;
for(Edge& e : adj[top.se])
if(cur[e.pos]==e.dir&&dist[e.to]>top.fi+e.weight) dist[e.to]=top.fi+e.weight, pq.ins(dist[e.to],e.to);
}
}
ll calc(){
memset(dist1,0x3f,sizeof(dist1));
memset(distN,0x3f,sizeof(distN));
dijkstra(1,dist1);
dijkstra(n,distN);
return dist1[n]+distN[1];
}
int main()
{
tt;
if(fopen((NAME + ".INP").c_str(), "r")) fo;
cin >> n >> m;
for(int i = 1; i<=m; ++i){
int x,y,z,cost;
cin >> x >> y >> z >> cost;
adj[x].pb(Edge(y,z,i,0)), adj[y].pb(Edge(x,z+cost,i,1));
}
for(int i = 1; i<=m; ++i){
cur[i]=1;
rs=min(rs,calc());
cur[i]=0;
}
if(rs>=1e18) rs=-1;
cout << rs;
}
Compilation message (stderr)
ho_t4.cpp: In function 'int main()':
ho_t4.cpp:3:19: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ho_t4.cpp:54:45: note: in expansion of macro 'fo'
54 | if(fopen((NAME + ".INP").c_str(), "r")) fo;
| ^~
ho_t4.cpp:3:63: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ho_t4.cpp:54:45: note: in expansion of macro 'fo'
54 | if(fopen((NAME + ".INP").c_str(), "r")) fo;
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |