#include #include typedef struct station{ int input; int output; } station; typedef struct pipe { int from; int to; } pipe; int main(){ int st, pipes; scanf("%d %d", &st, &pipes); station* tomb = (station*) malloc(st * sizeof(station)); pipe* tomb2 = (pipe*) malloc(pipes * sizeof(pipe)); int i1, i2; int begin = -1, end = -2; int i; for (i = 0; i < pipes; i++){ scanf("%d %d", &i1, &i2); tomb[i1-1].output++; tomb[i2-1].input++; tomb2[i].from = i1; tomb2[i].to = i2; } int count = 0; for (i = 0; i < st; i++){ if ((tomb[i].input != 0) && (tomb[i].output != 0)){ count += tomb[i].input - 1; } else if (tomb[i].input == 0) { begin = i + 1; } else if (tomb[i].output == 0){ end = i + 1; } } for (i = 0; i < pipes; i++){ if (tomb2[i].from == begin && tomb2[i].to == end){ count++; } } printf("%d\n", count); return 0; }