class Solution {
public:
int findJudge(int N, vector<vector<int>>& trust) {
if(trust.size()==0) {
if(N==1) return 1;
else return -1;
}
vector<vector<int>> v;
for(int i=0;i<N;i++) v.push_back(vector<int>());
for(int i=0;i<trust.size();i++) {
v[trust[i][0]-1].push_back(trust[i][1]-1);
}
int temp = 0;
for(int i=0;i<N;i++) {
if(v[i].size()==0) {
temp = i;
break;
}
}
int count = 0;
for(int i=0;i<N;i++) {
if(v[i].size()==0) continue;
if(find(v[i].begin(), v[i].end(), temp)==v[i].end()) return -1;
else count++;
}
if(count==N-1) return temp+1;
else return -1;
}
};