Submission #467435

#TimeUsernameProblemLanguageResultExecution timeMemory
467435OzyLove Polygon (BOI18_polygon)C++17
25 / 100
2094 ms11824 KiB
#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; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...