vitormartinotti

investigation

Oct 30th, 2025
1,021
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.47 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define pii pair<int,int>
  3. #define MAXN 10010
  4.  
  5. using namespace std;
  6.  
  7. const int MOD = (int)1e9+7;
  8.  
  9. vector<pii> grafo[MAXN];
  10.  
  11. int dist[MAXN], pai[MAXN], rota[MAXN], min_vrota[MAXN], max_vrota[MAXN];
  12. /*
  13. rota[i]: nro de caminhos minimos para chegar no vértice i
  14. min_vrota[i]: menor nro de vértices dentre as menores rotas até i
  15. max_vrota[i]: maior nro de vértices dentre as menores rotas até i
  16. */
  17.  
  18. void dijkstra(int s){
  19.     set<pii> q;
  20.     q.insert({0,s});
  21.     dist[s] = 0;
  22.     rota[s] = 1;
  23.     min_vrota[s] = 1;
  24.     max_vrota[s] = 1;
  25.  
  26.     while(!q.empty()){
  27.         int v = q.begin()->second;
  28.         q.erase(q.begin());
  29.         for(auto [w,u] : grafo[v]){
  30.             if(dist[v]+w < dist[u]){
  31.                 q.erase({dist[u],u});
  32.                 dist[u] = dist[v]+w;
  33.                 q.insert({dist[u],u});
  34.                 pai[u] = v;
  35.  
  36.                 rota[u] = rota[v];
  37.                 min_vrota[u] = min_vrota[v]+1;
  38.                 max_vrota[u] = max_vrota[v]+1;
  39.             }else if(dist[v]+w == dist[u]){
  40.                 rota[u] += rota[v];
  41.                 rota[u] %= MOD;
  42.                 min_vrota[u] = min(min_volta[u],min_vrota[v]+1);
  43.                 max_vrota[u] = max(max_vrota[u],max_vrota[v]+1);
  44.             }
  45.         }
  46.     }
  47. }
  48.  
  49. int main(){
  50.     int n, m; scanf("%d %d", &n, &m);
  51.  
  52.     for(int i = 0; i < m; i++){
  53.         int a, b, c; scanf("%d %d %d", &a, &b, &c);
  54.         grafo[a].push_back({c,b});
  55.     }
  56.  
  57.     //
  58. }
  59.  
Advertisement
Add Comment
Please, Sign In to add comment