#include <bits/stdc++.h> constexpr int HIGH = 1; constexpr int NONE = 0; constexpr int LOW = -1; struct Marker { int c[3] = {NONE,NONE,NONE}; }; Marker C[1000005]; int main() { std::ios_base::sync_with_stdio(0); int n; std::cin >> n; int m; std::cin >> m; for(int i=0; i<m; i++) { int a, b, k; std::cin >> a >> b >> k; a--; k--; C[a].c[k] += HIGH; C[b].c[k] += LOW; } int kv[3] = {0,0,0}; int r = 0; for(int i=0;i<n;i++) { for(int j=0;j<3;j++) { /*if(C[i].c[j] == HIGH) { kv[j]++; }*/ kv[j]+=C[i].c[j]; //std::clog << "C[" << i << "].c[" << j << "]=" << C[i].c[j] << "\t\t"; } /*for(int j=0;j<3;j++) { std::clog << "kv[" << j << "]=" << kv[j] << " "; }*/ if(kv[0]>0 && kv[1]>0 && kv[2]==0) { r++; //std::clog << "\tHIT"; } /*for(int j=0;j<3;j++) { if(C[i].c[j] == LOW) { kv[j]--; } }*/ //std::clog << "\n"; } std::cout << r << "\n"; return 0; }
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | #include <bits/stdc++.h> constexpr int HIGH = 1; constexpr int NONE = 0; constexpr int LOW = -1; struct Marker { int c[3] = {NONE,NONE,NONE}; }; Marker C[1000005]; int main() { std::ios_base::sync_with_stdio(0); int n; std::cin >> n; int m; std::cin >> m; for(int i=0; i<m; i++) { int a, b, k; std::cin >> a >> b >> k; a--; k--; C[a].c[k] += HIGH; C[b].c[k] += LOW; } int kv[3] = {0,0,0}; int r = 0; for(int i=0;i<n;i++) { for(int j=0;j<3;j++) { /*if(C[i].c[j] == HIGH) { kv[j]++; }*/ kv[j]+=C[i].c[j]; //std::clog << "C[" << i << "].c[" << j << "]=" << C[i].c[j] << "\t\t"; } /*for(int j=0;j<3;j++) { std::clog << "kv[" << j << "]=" << kv[j] << " "; }*/ if(kv[0]>0 && kv[1]>0 && kv[2]==0) { r++; //std::clog << "\tHIT"; } /*for(int j=0;j<3;j++) { if(C[i].c[j] == LOW) { kv[j]--; } }*/ //std::clog << "\n"; } std::cout << r << "\n"; return 0; } |