Advertisement
Guest User

velox

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