Submission #880818

#TimeUsernameProblemLanguageResultExecution timeMemory
880818vjudge1Love Polygon (BOI18_polygon)C++17
0 / 100
43 ms8904 KiB
#include <bits/stdc++.h> #define file_io freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout); #define fast_io ios::sync_with_stdio(false);cin.tie(0); #define what(x) cerr << #x << " is " << x << '\n'; #define kill(x) {cout << x << '\n'; return 0;} #define all(x) (x).begin(), (x).end() #define pii pair<int, int> #define pb push_back #define ll long long #define F first #define S second const ll inf = 1e18, mod = 1e9 + 7, delta = 1e9 + 9, SQ = 450, P = 6065621; using namespace std; const ll N = 2e5 + 10, LG = 31; int go[N], c; unordered_map<string, int> com; bool mark[N]; void dfs (int v) { c++; mark[v] = true; if (!mark[go[v]]) dfs(go[v]); } int main() { fast_io; int m, n = 0; cin >> m; while (m--) { string s, t; cin >> s >> t; if (!com[s]) com[s] = ++n; if (!com[t]) com[t] = ++n; go[com[s]] = com[t]; } if (n & 1) kill(-1); vector<int> cnt; for (int i = 1; i <= n; i++) if (!mark[i]) c = 0, dfs(i), cnt.pb(c); int ans = 0; int cntt = 0; for (auto u: cnt) { if (u & 1) cntt++; ans += u / 2; } ans += cntt; cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...