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
45
46
47
48
49
50
51
52
#include<iostream>
#include<vector>
using namespace std;

vector<int> invs[1000042];

bool is_green(int zol, int nieb, int czer) {
    return zol > 0 && nieb > 0 && czer == 0; 
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n,m;
    cin>>n>>m;

    int akt[] = {0, 0, 0, 0}; // nic, zol, nieb, czer

    int left, right, col;
    for (int i = 0; i < m; i++)
    {
        cin>>left>>right>>col;

        invs[left-1].push_back(col);
        invs[right-1].push_back(-col);
    }

    int result = 0;

    for (int i = 0; i < n; i++)
    {
        for (int val : invs[i])
        {
            if (val > 0) {
                akt[val]++;
            }
        }

        result += is_green(akt[1], akt[2], akt[3]);

        for (int val : invs[i])
        {
            if (val < 0) {
                akt[-val]--;
            }
        }
        
    }
    
    cout<<result<<"\n";
}