Submission #1026919

#TimeUsernameProblemLanguageResultExecution timeMemory
102691912345678Love Polygon (BOI18_polygon)C++17
29 / 100
228 ms27220 KiB
#include <bits/stdc++.h> using namespace std; const int nx=1e5+5; int n, t, vs[nx], l[nx], res, cnt, lv[nx], used[nx]; string su[nx], sv[nx]; map<string, int> mp; vector<int> d[nx]; void dfs(int u, int p) { for (auto v:d[u]) if (v!=p) dfs(v, u); if (u!=p&&!used[u]&&!used[p]) res--, used[u]=used[p]=1; } int main() { cin.tie(NULL)->sync_with_stdio(false); cin>>n; res=n; for (int i=1; i<=n; i++) cin>>su[i]>>sv[i], mp[su[i]]=mp[sv[i]]=0; if (n%2) return cout<<-1, 0; for (auto &[x, y]:mp) y=++t; for (int i=1; i<=n; i++) if (mp[su[i]]!=mp[sv[i]]) lv[mp[su[i]]]=1, d[mp[sv[i]]].push_back(mp[su[i]]); for (int i=1; i<=n; i++) if (!lv[i]) dfs(i, i); 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...