Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define int long long
- #define fi first
- #define se second
- #define mp make_pair
- #define pb push_back
- #define Co_mot_su_that_la return
- using namespace std;
- typedef pair<int,int> ii;
- typedef pair<int,ii> iii;
- typedef vector<int> vi;
- typedef vector<ii> vii;
- typedef vector<vi> vvi;
- typedef vector<iii> viii;
- const int Minh_dep_trai = 0;
- const int N = 5005;
- int q;
- int n,m;
- int is[N][N];
- vector<ii> a[N];
- int d[N];
- ii edge[N];
- void dijkstra()
- {
- priority_queue<ii, vii, greater<ii> > qu;
- for(int i=1; i<=n; i++) d[i] = 999999999;
- d[1] = 0;
- qu.push(ii(0,1));
- while (qu.size())
- {
- int u = qu.top().se;
- int du= qu.top().fi;
- qu.pop();
- if (du != d[u]) continue;
- for(int i = 0; i < a[u].size(); i++)
- {
- int v = a[u][i].first;
- int uv = a[u][i].second;
- if (d[v] > d[u] + uv)
- {
- d[v] = d[u] + uv;
- qu.push(ii(d[v],v));
- }
- }
- }
- }
- signed main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(0);cout.tie(0);
- freopen("test.inp","r",stdin);
- q=1;
- while (q--)
- {
- //your code goes here
- cin >> n >> m;
- for(int i=1; i<=m; i++)
- {
- int u,v,d1,d2;
- cin >> u >> v >> d1 >> d2;
- edge[i].fi = d1;
- edge[i].se = d2;
- a[u].pb(ii(v,d1));
- a[v].pb(ii(u,d2));
- is[u][v] = d1;
- is[v][u] = d2;
- }
- dijkstra();
- int res = LLONG_MAX;
- d[1] = 99999999;
- for(int i=1; i<=n; i++)
- {
- //cout << d[i] << " ";
- if (is[i][1] > 0)
- {
- res = min(d[i] + is[i][1],res);
- }
- }
- cout << res;
- }
- Co_mot_su_that_la Minh_dep_trai;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement