HELP! Silver USACO 2016 December Problem 2: Cities and States

Hey whoever is reading this Topic,

Can you please help me with “Cities and States”, Silver December 2016 Problem 2?
I have written my code, and to me, it seems perfectly fine, but it did not completely pass the test cases. Could you post anything errors that you found in my code below?

#include <iostream> 
#include <algorithm> 
#include <fstream> 
using namespace std; 

bool exist[2626][2626]; 
string cit[200000], sta[200000]; 

int num(string s) { 
	int a = (s[0]-65)*100, b = (s[1]-65); 
	return a+b; 
} 

int main() 
{ 
	long long N, pairs = 0; cin >> N; 
	for (int n = 0; n < N; n++) { 
		cin >> cit[n] >> sta[n]; 
		exist[num(cit[n])][num(sta[n])] = true; 
	} 

	for (int i = 0; i < N; i++) { 
		if (num(cit[i]) != num(sta[i])) { 
			if (exist[num(cit[i])][num(sta[i])]) { 
				if (exist[num(sta[i])][num(cit[i])]) { 
					pairs++; 
					exist[num(cit[i])][num(sta[i])] = false; 
					exist[num(sta[i])][num(cit[i])] = false; 
				} 
			} 
		} 
	} cout << pairs << endl; 
} 

If you did not fully understand what my code did there, I created a sort of boolean map from a 2D array, called “exists”.

exists[num(city_name)][num(state_name)] is whether or not there exists a city called “city_name” that is in the state, “state_name”.

Thanks in advance! :blush:
Yours,
peppersniffer

Have you tried downloading the test cases?

Yes. N is always over 1000 :expressionless:

Try this test case:

3
MIAMI FL
MILLAS TX
FLINT MI

The answer should be 2(?) IDK, it’s been some time since I’ve worked on this problem.