#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&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 |
2089 ms |
204 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2068 ms |
11004 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2089 ms |
204 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |