1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
using namespace std;
const int MAXN = 1000100;
struct query{
    int c_add,z_add,n_add;
    int c_sub,z_sub,n_sub;
};
query tab[MAXN];
int red,green,blue;
int wynik = 0;
int main(int argc, const char * argv[]) {
    ios_base :: sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n; cin >> n;
    int m; cin >> m;
    for(int i = 0 ; i < m; i++){
        int x,y; cin >> x >> y;
        int color; cin >> color;
        if(color == 1){
            tab[x].z_add++;
            tab[y].z_sub--;
        }else if(color == 2){
            tab[x].n_add++;
            tab[y].n_sub--;
        }else{
            tab[x].c_add++;
            tab[y].c_sub--;
        }
    }
    for(int i = 1 ; i <= n; i++){
        if(tab[i].c_add > 0)
            red += tab[i].c_add;
        if(tab[i].n_add > 0)
        blue += tab[i].n_add;
        green += tab[i].z_add;
        if(!red && blue && green)
            wynik++;
        red += tab[i].c_sub;
        blue += tab[i].n_sub;
        green += tab[i].z_sub;
    }
    cout << wynik << endl;
    return 0;
}