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
#include <bits/stdc++.h>

using namespace std;
vector<int> dod[1000100], usu[1000100];
int c, d, e, a, b, w, licz[41];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> a >> b;
    for (int i = 0; i < b; i++)
    {
        cin >> c >> d >> e;
        c--;
        d--;
        dod[c].push_back(e);
        usu[d].push_back(e);
    }
    for (int i = 0; i < a; i++)
    {
        for(int z=0;z<dod[i].size();z++)
        {
            licz[dod[i][z]]++;
        }
        if (licz[1] > 0 && licz[2] > 0 && licz[3] == 0)
        {
            w++;
        }
        for(int z=0;z<usu[i].size();z++)
        {
            licz[usu[i][z]]--;
        }
    }
    cout << w << "\n";
    return 0;
}