Submission #916592

#TimeUsernameProblemLanguageResultExecution timeMemory
916592LCJLYLove Polygon (BOI18_polygon)C++14
0 / 100
252 ms14064 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define ld long double #define show(x,y) cout << y << " " << #x << endl; #define show2(x,y,i,j) cout << y << " " << #x << " " << j << " " << #i << endl; #define show3(x,y,i,j,p,q) cout << y << " " << #x << " " << j << " " << #i << " " << q << " " << #p << endl; #define show4(x,y) for(auto it:x) cout << it << " "; cout << #y << endl; typedef pair<int,int>pii; vector<int>adj[100005]; map<string,int>mp; int ptr=0; int sz=0; bool visited[100005]; void dfs(int index){ sz++; visited[index]=true; for(auto it:adj[index]){ if(visited[it]) continue; dfs(it); } } void solve(){ int n; cin >> n; string s,s2; for(int x=0;x<n;x++){ cin >> s >> s2; if(mp.find(s)==mp.end()){ mp[s]=ptr++; } if(mp.find(s2)==mp.end()){ mp[s2]=ptr++; } adj[mp[s]].push_back(mp[s2]); adj[mp[s2]].push_back(mp[s]); } int counter=0; for(int x=0;x<ptr;x++){ if(visited[x]) continue; sz=0; dfs(x); counter+=(sz+1)/2; } if(ptr%2) cout << -1; else cout << counter; } int32_t main(){ ios::sync_with_stdio(0); cin.tie(0); int t=1; //cin >> t; while(t--){ solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...