제출 #391676

#제출 시각아이디문제언어결과실행 시간메모리
391676VictorLove Polygon (BOI18_polygon)C++17
25 / 100
194 ms32716 KiB
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = a; i < b; ++i) #define per(i, a, b) for (int i = b - 1; i >= a; --i) #define trav(a, x) for (auto& a : x) #define sz(a) a.size() typedef pair<int, int> ii; typedef long long ll; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<vi> vvi; unordered_map<string, string> people; unordered_set<string> vis; int si; void dfs(string person){ if(vis.count(person))return; vis.insert(person); ++si; dfs(people[person]); } int main() { cin.tie(0)->sync_with_stdio(0); int n; cin >> n; if (n & 1) { cout << -1 << endl; return 0; } int ans=0; string n1, n2; rep(i, 0, n) { cin >> n1 >> n2; people.emplace(n1, n2); if (n1!=n2&&people.count(n2) && people[n2] == n1) { people.erase(n1); people.erase(n2); } } trav(person,people){ si=0; dfs(person.first); ans+=(si+1)>>1; } cout<<ans<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...