Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <algorithm>
- #include <vector>
- #include <queue>
- #define task "BAI2CDT18"
- using namespace std;
- using ll = long long;
- using ld = long double;
- const int N = 5e3 + 2;
- struct Edge
- {
- int v;
- ll w;
- Edge() {}
- Edge(int v, ll w)
- {
- this->v = v;
- this->w = w;
- }
- };
- vector<Edge> adj[N];
- const ll Inf = 1e18;
- int n, m;
- ll d[N], f[N];
- void Read()
- {
- cin >> n >> m;
- for (int i = 1; i <= m; ++i)
- {
- int t, u, v;
- ll l;
- cin >> t >> u >> v >> l;
- adj[u].push_back(Edge(v, l));
- if (t == 2)
- adj[v].push_back(Edge(u, l));
- }
- }
- void Init()
- {
- fill_n(d, N, Inf);
- d[1] = 0;
- f[1] = 1;
- }
- bool Relax(int par, int son, ll w)
- {
- if (d[son] > d[par] + w)
- {
- d[son] = d[par] + w;
- f[son] = f[par];
- return true;
- }
- if (d[son] == d[par] + w)
- f[son] += f[par];
- return false;
- }
- void Dijkstra()
- {
- Init();
- struct Tque
- {
- int v;
- ll w;
- Tque() {}
- Tque(int v, ll w)
- {
- this->v = v;
- this->w = w;
- }
- bool operator<(const Tque &a) const
- {
- return w > a.w;
- }
- bool Valid()
- {
- return d[v] == w;
- }
- };
- priority_queue<Tque> s;
- s.push(Tque(1, 0));
- while (s.size())
- {
- Tque c = s.top();
- s.pop();
- if (!c.Valid())
- continue;
- for (auto i : adj[c.v])
- if (Relax(c.v, i.v, i.w))
- s.push(Tque(i.v, d[i.v]));
- }
- }
- void Solve()
- {
- Dijkstra();
- cout << f[n] << " " << d[n];
- }
- int32_t main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- if (fopen(task ".INP", "r"))
- freopen(task ".INP", "r", stdin),
- freopen(task ".OUT", "w", stdout);
- Read();
- Solve();
- }
Add Comment
Please, Sign In to add comment