Advertisement
Ginger_samurai

Untitled

May 24th, 2020
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.72 KB | None | 0 0
  1. #include<vector>
  2. #include <string>
  3. #include<algorithm>
  4. #include <iostream>
  5. #include <queue>
  6. #include<set>
  7. #include<cmath>
  8. #include<math.h>
  9. using namespace std;
  10. #define ll unsigned int
  11. #define pll pair<long long, long long>
  12. #define mp make_pair
  13. #define pb push_back
  14. #define all(a) a.begin(), a.end()
  15. #define rall(a) a.rbegin(), a.rend()
  16. #define cin(a) for(ll ghgh = 0; ghgh<a.size(); ghgh++) cin»a[ghgh];
  17. #define pcin(a) for(ll ghgh = 0; ghgh<a.size(); ghgh++) cin»a[ghgh].first»a[ghgh].second;
  18. #define cout(a) for(ll ghgha = 0; ghgha<a.size(); ghgha++) cout<<a[ghgha]<<" ";
  19. #define pcout(a) for(ll ghgha = 0; ghgha<a.size(); ghgha++) cout«a[ghgha].first«" "«a[ghgha].second«endl;
  20. const ll inf = 1e9 + 123, llinf = 1e18 + 123;
  21. void xru() {
  22.     setlocale(LC_ALL, "rus");
  23.     /*freopen(".in", "r", stdin);
  24.     freopen(".out", "w", stdout);*/
  25.     ios_base::sync_with_stdio(false);
  26.     cin.tie(NULL);
  27.     cout.tie(NULL);
  28. }
  29.  
  30.  
  31. void bfsa(vector<vector<ll>>& g, vector<ll>& dist) {
  32.     ll n = g.size();
  33.     vector<ll>used(n, false);
  34.     dist[0] = 0;
  35.     used[0] = true;
  36.     queue<ll>q;
  37.     q.push(0);
  38.     while (!q.empty()) {
  39.         ll x = q.front();
  40.         q.pop();
  41.         for (ll i = 0; i < g[x].size(); i++) {
  42.             ll to = g[x][i];
  43.             if (!used[to]) {
  44.                 dist[to] = dist[x] + 1;
  45.                 used[to] = true;
  46.                 q.push(to);
  47.  
  48.             }
  49.         }
  50.     }
  51.    
  52. }
  53. void bfsb(vector<vector<ll>>& g, vector<ll>& dist) {
  54.     ll n = g.size();
  55.     vector<ll>used(n, false);
  56.     dist[n-1] = 0;
  57.     used[n-1] = true;
  58.     queue<ll>q;
  59.     q.push(n-1);
  60.     while (!q.empty()) {
  61.         ll x = q.front();
  62.         q.pop();
  63.         for (ll i = 0; i < g[x].size(); i++) {
  64.             ll to = g[x][i];
  65.             if (!used[to]) {
  66.                 dist[to] = dist[x] + 1;
  67.                 used[to] = true;
  68.                 q.push(to);
  69.  
  70.             }
  71.         }
  72.     }
  73.  
  74. }
  75. void newg(vector<vector<ll>>& lg, vector<vector<ll>>& lcheck, vector<vector<ll>>& g, vector<vector<ll>>& check, vector<ll>& dista, vector<ll>& distb) {
  76.     ll n = g.size();
  77.     vector<ll>dist(n, inf);
  78.     vector<ll>used(n, false);
  79.     queue<ll>q;
  80.     dist[0] = 0;
  81.     used[0] = true;
  82.     q.push(0);
  83.     while (!q.empty()) {
  84.         ll x = q.front();
  85.         q.pop();
  86.         for (ll i = 0; i < g[x].size(); i++) {
  87.             ll to = g[x][i];
  88.             if (!used[to]) {
  89.                 dist[to] = dist[x] + 1;
  90.                 used[to] = true;
  91.                 q.push(to);
  92.                 if (dista[to] + distb[to] == dista[n - 1]) {
  93.                     lg[x].push_back(to);
  94.                     lg[to].push_back(x);
  95.                     lcheck[x][to] = check[x][to];
  96.                     lcheck[to][x] = lcheck[x][to];
  97.  
  98.                 }
  99.             }
  100.             else if (dist[x] + 1 == dist[to]) {
  101.                 if (dista[to] + distb[to] == dista[n - 1]) {
  102.                     lg[x].push_back(to);
  103.                     lg[to].push_back(x);
  104.                     lcheck[x][to] = check[x][to];
  105.                     lcheck[to][x] = lcheck[x][to];
  106.  
  107.                 }
  108.             }
  109.         }
  110.     }
  111. }
  112.  
  113. bool vectcomp(vector<ll>& a, vector<ll>& b) {
  114.     for (ll i = 0; i < min(a.size(), b.size()); i++) {
  115.         if (a[i] < b[i]) {
  116.             return true;
  117.         }
  118.         if (a[i] > b[i]) {
  119.             return false;
  120.         }
  121.     }
  122.     if (a.size() < b.size()) {
  123.         return true;
  124.     }
  125.     return false;
  126. }
  127.  
  128. void A(vector<vector<ll>>& g, vector<vector<ll>>& check,vector<ll>& ans) {
  129.     ll n = g.size();
  130.     vector<vector<ll>>minl(n);
  131.     vector<ll>dist(n, inf);
  132.     vector<ll>used(n, false);
  133.     queue<ll>q;
  134.     q.push(0);
  135.     used[0] = true;
  136.     dist[0] = 0;
  137.     while (!q.empty()) {
  138.         ll x = q.front();
  139.         q.pop();
  140.         for (ll i = 0; i < g[x].size(); i++) {
  141.             ll to = g[x][i];
  142.             if (!used[to]) {
  143.                 dist[to] = dist[x] + 1;
  144.                 used[to] = true;
  145.                 minl[to] = minl[x];
  146.                 minl[to].push_back(check[x][to]);
  147.                 q.push(to);
  148.             }
  149.             else {
  150.                 if (dist[to] == dist[x] + 1) {
  151.                     vector<ll>a = minl[x];
  152.                     a.push_back(check[x][to]);
  153.                     if (vectcomp(a, minl[to])) {
  154.                         minl[to] = a;
  155.                                             q.push(to);
  156.                     }
  157.  
  158.                 }
  159.             }
  160.         }
  161.     }
  162.     ans = minl[n - 1];
  163. }
  164.  
  165.  
  166. int main()
  167. {
  168.     xru();
  169.     cout << sizeof(unsigned int);
  170.     /*
  171.     ll n, m;
  172.     cin >> n >> m;
  173.     vector<ll>x(m), y(m), cnt(m);
  174.     vector<vector<ll>>check(n, vector<ll>(n, inf));
  175.     for (ll i = 0; i < m; i++) {
  176.         cin >> x[i] >> y[i] >> cnt[i];
  177.         x[i]--, y[i]--;
  178.         if (x[i] == y[i]) {
  179.             continue;
  180.         }
  181.         check[ x[i] ][ y[i] ] = min( check[ x[i] ][ y[i] ], cnt[i]);
  182.         check[y[i]][x[i]] = check[x[i]][y[i]];
  183.        // cout<< check[y[i]][x[i]]<<endl;
  184.     }
  185.     vector<vector<ll>>g(n);
  186.     vector<vector<bool>>usedcheck(n, vector<bool>(n, false));
  187.     for (ll i = 0; i < m; i++) {
  188.         if (x[i] == y[i]) {
  189.             continue;
  190.         }
  191.        // cout << x[i]+1 << " " << y[i]+1 << endl;
  192.         if (!usedcheck[x[i]][y[i]]) {
  193.             g[x[i]].push_back(y[i]);
  194.             g[y[i]].push_back(x[i]);
  195.             usedcheck[x[i]][y[i]] = true;
  196.             usedcheck[y[i]][x[i]] = true;
  197.         }
  198.     }
  199.     vector<ll>dista(n, inf), distb(n, inf);
  200.     bfsa(g, dista), bfsb(g, distb);
  201.     vector<vector<ll>>lg(n), lcheck(n, vector<ll>(n, inf));
  202.     newg(lg, lcheck, g, check, dista, distb);
  203.     vector<ll>ans;
  204.     A(lg, lcheck, ans);
  205.     cout << ans.size() << endl;
  206.     cout(ans);*/
  207. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement