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
| #include <bits/stdc++.h> #define ll long long #define ld long double #define N 1005 #define FOR(i,n) for(int i=0;i<n;i++) #define pii pair<int,int> using namespace std;
void solve(){ int wait[N][N];memset(wait,0,sizeof(wait)); int m,ans = 0;cin>>m; for(int i=0;i<m;i++){ int a,b;cin>>a>>b; if(wait[b][a]>0){ ans++;wait[b][a]--; } else wait[a][b]++; } cout<<ans<<endl; }
int main(){ int t;cin>>t; while(t--){ solve(); } }
|