Advertisement
Guest User

velox

a guest
May 4th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. #define MAXN 10000
  7.  
  8. struct arco_t {
  9.     int a;
  10.     int vel;
  11. };
  12.  
  13. int N, M, counter = 0;
  14. bool visited[MAXN+1];
  15. vector<arco_t> adj[MAXN+1];
  16.  
  17. int dfs_poveri(int u) {
  18.     int massima_arco = 0;
  19.     visited[u] = true;
  20.     for(auto x: adj[u]) {
  21.         if(x.vel > massima_arco)
  22.             massima_arco = x.vel;
  23.     }
  24.     return massima_arco;
  25. }
  26.  
  27. void resolution() {
  28.     int max_memo = 0;
  29.     for(int i = 0; i < N; i++) {
  30.         if(!visited[i]) {
  31.             int massimo = dfs_poveri(i);
  32.             if(massimo <= max_memo) return;
  33.             max_memo = massimo;
  34.             counter++;
  35.         }
  36.     }
  37. }
  38.  
  39. int main() {
  40.     freopen("input.txt", "r", stdin);
  41.     freopen("output.txt", "w", stdout);
  42.     scanf("%d%d", &N, &M);
  43.     for(int i = 0, da, a, velocita; i < M; i++) {
  44.         scanf("%d%d%d", &da, &a, &velocita);
  45.         adj[da].push_back({a, velocita});
  46.     }
  47.     resolution();
  48.     printf("%d", counter);
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement