#include <bits/stdc++.h> using namespace std; const int N = 1e5 * 5 + 123; int n,x,a,b; int jeden[N],dwa[N]; int res; int main () { ios_base::sync_with_stdio(0); cin >> n; for (int i = 1;i <= n;i++){ cin >> x; if (x == 1){ cin >> a >> b; jeden[N]++; } else{ cin >> a >> b; dwa[N]++; } } for (int i = 1;i <= n;i++){ if (jeden[i] >= 2 ){ res += jeden[i] - 1; } else if ( dwa[i] >= 2) { res += dwa[i] - 1; } else if (jeden[i] == dwa[i] && jeden[i] == 1){ res ++; } } cout << res-1 << '\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 | #include <bits/stdc++.h> using namespace std; const int N = 1e5 * 5 + 123; int n,x,a,b; int jeden[N],dwa[N]; int res; int main () { ios_base::sync_with_stdio(0); cin >> n; for (int i = 1;i <= n;i++){ cin >> x; if (x == 1){ cin >> a >> b; jeden[N]++; } else{ cin >> a >> b; dwa[N]++; } } for (int i = 1;i <= n;i++){ if (jeden[i] >= 2 ){ res += jeden[i] - 1; } else if ( dwa[i] >= 2) { res += dwa[i] - 1; } else if (jeden[i] == dwa[i] && jeden[i] == 1){ res ++; } } cout << res-1 << '\n'; return 0; } |