I am not able to figure out the error? can somebody please help me with this
#include<bits/stdc++.h>
using namespace std;
const int N = 2 * (1e5 + 5);
int boys[N];
int girls[N];
vector B;
vector G;
int fun(int a, int b, int k) {
for(int i = 0; i < k; i++) {
B.push_back(boys[i]);
G.push_back(girls[i]);
}
if(k < 2) return 0;
int ans = 0;
for(int i = 0; i < k - 1; i++) {
int one = B[i];
int two = G[i];
int x = count(B.begin() + i + 1, B.end(), one);
int y = count(G.begin() + i + 1, G.end(), two);
int cnt = k - (i + 1 + x + y);
ans += cnt;
}
B.clear();
G.clear();
return ans;
}
void solve() {
int a, b, k;
cin>>a>>b>>k;
for(int i = 0; i < k; i++) {
cin>>boys[i];
}
for(int j = 0; j < k; j++) {
cin>>girls[j];
}
cout<<fun(a, b, k)<<endl;
}
int main() {
int t;
cin>>t;
while(t--) solve();
return 0;
}
which problem?? send the link
My solution is on the top. Help me to rectify the error
You are recounting certain pairs. So, you need to maintain a frequency or degree for each boy and girl and then select the pairs.
Link to my submission:
Thanks a lot.