Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <vector>
- using namespace std;
- #define MAXN 10000
- struct arco_t {
- int a;
- int vel;
- };
- int N, M, counter = 0;
- bool visited[MAXN+1];
- vector<arco_t> adj[MAXN+1];
- int dfs_poveri(int u) {
- int massima_arco = 0;
- visited[u] = true;
- for(auto x: adj[u]) {
- if(x.vel > massima_arco)
- massima_arco = x.vel;
- }
- return massima_arco;
- }
- void resolution() {
- int max_memo = 0;
- for(int i = 0; i < N; i++) {
- if(!visited[i]) {
- int massimo = dfs_poveri(i);
- if(massimo <= max_memo) return;
- max_memo = massimo;
- counter++;
- }
- }
- }
- int main() {
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- scanf("%d%d", &N, &M);
- for(int i = 0, da, a, velocita; i < M; i++) {
- scanf("%d%d%d", &da, &a, &velocita);
- adj[da].push_back({a, velocita});
- }
- resolution();
- printf("%d", counter);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment