#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define repa(i,a,b) for(int i = (a); i >= (b); i--)
#define lli long long int
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "
#define MAX 100000
string A,B;
lli n,a,b,cont,impares,res;
map<string,lli> mapa;
lli amor[MAX+2],visitados[MAX+2];
lli dfs(lli ini) {
lli act = amor[ini];
lli cant = 1;
visitados[ini] = 1;
while (act != ini) {
visitados[act] = 1;
cant++;
act = amor[act];
}
if (cant == 2) return 0;
if (cant&1) impares++;
cant++;
cant /= 2;
return cant;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
cont = 1;
rep(i,1,n) {
cin >> A >> B;
if (mapa.find(A) == mapa.end()) mapa[A] = cont++;
a = mapa[A];
if (mapa.find(B) == mapa.end()) mapa[B] = cont++;
b = mapa[B];
amor[a] = b;
}
res = 0;
impares = 0;
rep(i,1,n) if (visitados[i] == 0) res += dfs(i);
if (impares&1) cout << -1;
else cout << res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2094 ms |
204 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
324 KB |
Output is correct |
4 |
Correct |
211 ms |
11800 KB |
Output is correct |
5 |
Correct |
206 ms |
11824 KB |
Output is correct |
6 |
Correct |
238 ms |
11812 KB |
Output is correct |
7 |
Correct |
210 ms |
11812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2089 ms |
8900 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2094 ms |
204 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |