Submission #829759

#TimeUsernameProblemLanguageResultExecution timeMemory
829759Darren0724Love Polygon (BOI18_polygon)C++17
0 / 100
185 ms11068 KiB
#include<bits/stdc++.h> using namespace std; const int N=100005; map<string,int> m; vector<int> vis(N); vector<int> v(N); int cnt=0; int id(string s){ if(m.count(s)){ return m[s]; } int p=m.size(); m[s]=p; return p; } void dfs(int k){ vis[k]=1; cnt++; if(!vis[v[k]]){ dfs(v[k]); } } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n;cin>>n; if(n&1){ cout<<-1<<endl; return 0; } for(int i=0;i<n;i++){ string a,b;cin>>a>>b; v[id(a)]=id(b); } int ans=0; for(int i=0;i<n;i++){ if(!vis[i]){ cnt=0; dfs(i); if(cnt==3){ continue; } ans+=(cnt+1)/2; } } cout<<ans<<endl; 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...