//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 numUsed, int cnt) {
if(numUsed == n) {
ans = min(ans, cnt);
return;
}
for(int i = 0; i < n; i ++) {
if(used[i] == 1) continue;
for(int j = i + 1; j < n; j ++) {
if(used[j] == 1) continue;
int newcnt = cnt;
if(who[i] != j) newcnt ++;
if(who[j] != i) newcnt ++;
used[i] = 1;
used[j] = 1;
f(numUsed + 2, newcnt);
used[i] = 0;
used[j] = 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[u]] = mp[v];
}
if(n % 2 == 1) {
cout << "-1";
return 0;
}
f(0,0);
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2033 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Execution timed out |
2066 ms |
13416 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2051 ms |
13232 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2033 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |