//Bismi Allah
#include "bits/stdc++.h"
using namespace std;
signed main () {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, ans = 1e9;
cin >> n;
vector <int> who(n, -1), used(n, 0);
map <string,int> mp;
// function<void(int,int)> f=[&](int v, int cnt) {
// used[v]=1;
// if(count(used.begin(), used.end(), 1) == used.size()) {
// ans = min(ans, cnt);
// used[v]=0;
// return;
// }
// for(int i = 0; i < used.size(); i ++) {
// if(used[i]) continue;
// if(who[i] == v && who[v] == i) {
// }
// }
// used[v]=0;
// };
int cnt = 0;
for(int i = 0; i < n; i ++) {
string u, v;
cin >> u >> v;
if(mp.count(u) == 0) mp[u] = mp.size();
if(mp.count(v) == 0) mp[v] = mp.size();
if(mp[u] == mp[v]) cnt ++;
who[mp[v]] = mp[u];
}
if(n % 2 == 1) {
cout << "-1";
return 0;
}
cout << cnt+(n-cnt)/2;
return 0;
}
Compilation message
polygon.cpp: In function 'int main()':
polygon.cpp:9:9: warning: unused variable 'ans' [-Wunused-variable]
9 | int n, ans = 1e9;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
460 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
161 ms |
11196 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |