Submission #731640

#TimeUsernameProblemLanguageResultExecution timeMemory
731640shadow_samiLove Polygon (BOI18_polygon)C++17
0 / 100
98 ms15536 KiB
#include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; typedef long long int ll; typedef vector<ll> vi; typedef pair<ll,ll> pi; #define ff first #define ss second #define all(a) a.begin(),a.end() #define fip(a,b) for(ll i = a; i < b ; i++) #define fjp(a,b) for(ll j = a; j < b ; j++) #define fp(k,a,b) for(ll k = a; k < b ; k++) #define fin(a,b) for(ll i = a; i >= b ; i--) #define fjn(a,b) for(ll i = a; j >= b ; j--) #define fn(k,a,b) for(ll k = a; k >= b ; k--) #define fx(a) for(auto x : a) #define ordered_set tree<pi,null_type,less<pi>,rb_tree_tag,tree_order_statistics_node_update> #define total_one(k) __builtin_popcount(k) #define back_zero(k) __builtin_ctzll(k) #define front_zero(k) __builtin_clzll(k) #define nli "\n" ll n,m,ans,sum,res,cnt,tptp,tp,tp2; const ll mx = 1e5 + 5; const ll mod = 1e9 + 7; unordered_map<string,ll> hashe; string k1,k2; vi adj[mx]; bool vis[mx]; void dfs(ll u){ tp++; vis[u] = 1; fx(adj[u]) if(!vis[x]) dfs(x); } int main(){ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); // #ifdef code // freopen("input1.txt","r",stdin); // freopen("output1.txt","w",stdout); // freopen("error1.txt","w",stderr); // #endif cin>>n; tptp = 0; ans = 0; cnt = 0; fip(1,n+1){ cin>>k1>>k2; if(!hashe.count(k1)){ cnt++; hashe[k1] = cnt; } if(!hashe.count(k2)){ cnt++; hashe[k2] = cnt; } adj[hashe[k1]].push_back(hashe[k2]); } if(n&1){ cout<<-1<<nli; return 0; } fip(1,n+1){ if(!vis[i]){ tp = 0; dfs(i); ans += (tp / 2); ans += (tp & 1); } } cout<<ans<<nli; // cerr << "Time elapsed : " << setprecision(6) << 100.00 * clock() / CLOCKS_PER_SEC << "ms\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...