Submission #880816

#TimeUsernameProblemLanguageResultExecution timeMemory
880816vjudge1Love Polygon (BOI18_polygon)C++17
0 / 100
68 ms13628 KiB
#include <bits/stdc++.h> #define pb push_back using namespace std; const int N = 1e5 + 10; int n, t, cnt, ans; bool mark[N]; vector<int> G[N]; unordered_map<string, int> mp; void dfs(int v) { mark[v] = true; cnt++; int u = G[v][0]; while (!mark[u]) cnt++, mark[u] = true, u = G[u][0]; return; } int main() { ios:: sync_with_stdio(0), cin.tie(0); cin >> n; for (int i = 0; i < n; i++) { string u, v; cin >> u >> v; if (mp[u] == 0) mp[u] = ++t; if (mp[v] == 0) mp[v] = ++t; G[mp[u]].pb(mp[v]); } for (int i = 1; i <= n; i++) if (!mark[i]) { dfs(i); if (cnt ^ 2) ans += (cnt + 1) / 2; cnt = 0; } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...