Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<vector>
- #include <string>
- #include<algorithm>
- #include <iostream>
- #include <queue>
- #include<set>
- #include<cmath>
- #include<math.h>
- using namespace std;
- #define ll unsigned int
- #define pll pair<long long, long long>
- #define mp make_pair
- #define pb push_back
- #define all(a) a.begin(), a.end()
- #define rall(a) a.rbegin(), a.rend()
- #define cin(a) for(ll ghgh = 0; ghgh<a.size(); ghgh++) cin»a[ghgh];
- #define pcin(a) for(ll ghgh = 0; ghgh<a.size(); ghgh++) cin»a[ghgh].first»a[ghgh].second;
- #define cout(a) for(ll ghgha = 0; ghgha<a.size(); ghgha++) cout<<a[ghgha]<<" ";
- #define pcout(a) for(ll ghgha = 0; ghgha<a.size(); ghgha++) cout«a[ghgha].first«" "«a[ghgha].second«endl;
- const ll inf = 1e9 + 123, llinf = 1e18 + 123;
- void xru() {
- setlocale(LC_ALL, "rus");
- /*freopen(".in", "r", stdin);
- freopen(".out", "w", stdout);*/
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- cout.tie(NULL);
- }
- void bfsa(vector<vector<ll>>& g, vector<ll>& dist) {
- ll n = g.size();
- vector<ll>used(n, false);
- dist[0] = 0;
- used[0] = true;
- queue<ll>q;
- q.push(0);
- while (!q.empty()) {
- ll x = q.front();
- q.pop();
- for (ll i = 0; i < g[x].size(); i++) {
- ll to = g[x][i];
- if (!used[to]) {
- dist[to] = dist[x] + 1;
- used[to] = true;
- q.push(to);
- }
- }
- }
- }
- void bfsb(vector<vector<ll>>& g, vector<ll>& dist) {
- ll n = g.size();
- vector<ll>used(n, false);
- dist[n-1] = 0;
- used[n-1] = true;
- queue<ll>q;
- q.push(n-1);
- while (!q.empty()) {
- ll x = q.front();
- q.pop();
- for (ll i = 0; i < g[x].size(); i++) {
- ll to = g[x][i];
- if (!used[to]) {
- dist[to] = dist[x] + 1;
- used[to] = true;
- q.push(to);
- }
- }
- }
- }
- void newg(vector<vector<ll>>& lg, vector<vector<ll>>& lcheck, vector<vector<ll>>& g, vector<vector<ll>>& check, vector<ll>& dista, vector<ll>& distb) {
- ll n = g.size();
- vector<ll>dist(n, inf);
- vector<ll>used(n, false);
- queue<ll>q;
- dist[0] = 0;
- used[0] = true;
- q.push(0);
- while (!q.empty()) {
- ll x = q.front();
- q.pop();
- for (ll i = 0; i < g[x].size(); i++) {
- ll to = g[x][i];
- if (!used[to]) {
- dist[to] = dist[x] + 1;
- used[to] = true;
- q.push(to);
- if (dista[to] + distb[to] == dista[n - 1]) {
- lg[x].push_back(to);
- lg[to].push_back(x);
- lcheck[x][to] = check[x][to];
- lcheck[to][x] = lcheck[x][to];
- }
- }
- else if (dist[x] + 1 == dist[to]) {
- if (dista[to] + distb[to] == dista[n - 1]) {
- lg[x].push_back(to);
- lg[to].push_back(x);
- lcheck[x][to] = check[x][to];
- lcheck[to][x] = lcheck[x][to];
- }
- }
- }
- }
- }
- bool vectcomp(vector<ll>& a, vector<ll>& b) {
- for (ll i = 0; i < min(a.size(), b.size()); i++) {
- if (a[i] < b[i]) {
- return true;
- }
- if (a[i] > b[i]) {
- return false;
- }
- }
- if (a.size() < b.size()) {
- return true;
- }
- return false;
- }
- void A(vector<vector<ll>>& g, vector<vector<ll>>& check,vector<ll>& ans) {
- ll n = g.size();
- vector<vector<ll>>minl(n);
- vector<ll>dist(n, inf);
- vector<ll>used(n, false);
- queue<ll>q;
- q.push(0);
- used[0] = true;
- dist[0] = 0;
- while (!q.empty()) {
- ll x = q.front();
- q.pop();
- for (ll i = 0; i < g[x].size(); i++) {
- ll to = g[x][i];
- if (!used[to]) {
- dist[to] = dist[x] + 1;
- used[to] = true;
- minl[to] = minl[x];
- minl[to].push_back(check[x][to]);
- q.push(to);
- }
- else {
- if (dist[to] == dist[x] + 1) {
- vector<ll>a = minl[x];
- a.push_back(check[x][to]);
- if (vectcomp(a, minl[to])) {
- minl[to] = a;
- q.push(to);
- }
- }
- }
- }
- }
- ans = minl[n - 1];
- }
- int main()
- {
- xru();
- cout << sizeof(unsigned int);
- /*
- ll n, m;
- cin >> n >> m;
- vector<ll>x(m), y(m), cnt(m);
- vector<vector<ll>>check(n, vector<ll>(n, inf));
- for (ll i = 0; i < m; i++) {
- cin >> x[i] >> y[i] >> cnt[i];
- x[i]--, y[i]--;
- if (x[i] == y[i]) {
- continue;
- }
- check[ x[i] ][ y[i] ] = min( check[ x[i] ][ y[i] ], cnt[i]);
- check[y[i]][x[i]] = check[x[i]][y[i]];
- // cout<< check[y[i]][x[i]]<<endl;
- }
- vector<vector<ll>>g(n);
- vector<vector<bool>>usedcheck(n, vector<bool>(n, false));
- for (ll i = 0; i < m; i++) {
- if (x[i] == y[i]) {
- continue;
- }
- // cout << x[i]+1 << " " << y[i]+1 << endl;
- if (!usedcheck[x[i]][y[i]]) {
- g[x[i]].push_back(y[i]);
- g[y[i]].push_back(x[i]);
- usedcheck[x[i]][y[i]] = true;
- usedcheck[y[i]][x[i]] = true;
- }
- }
- vector<ll>dista(n, inf), distb(n, inf);
- bfsa(g, dista), bfsb(g, distb);
- vector<vector<ll>>lg(n), lcheck(n, vector<ll>(n, inf));
- newg(lg, lcheck, g, check, dista, distb);
- vector<ll>ans;
- A(lg, lcheck, ans);
- cout << ans.size() << endl;
- cout(ans);*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement