Submission #731649

#TimeUsernameProblemLanguageResultExecution timeMemory
731649shadow_samiLove Polygon (BOI18_polygon)C++17
29 / 100
2067 ms26860 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]; vi reverse_adj[mx]; bool vis[mx]; ll find_root(ll k){ if(adj[k].front() == k) return k; fx(adj[k]) return find_root(x); } ll dfs(ll u,ll root){ vis[u] = 1; ll sz = 1; fx(reverse_adj[u]) if(!vis[x]){ sz += dfs(x,root); } if(sz>=2){ ans += sz - 1; sz = 0; } if(sz==1 && u == root){ ans++; } return sz; } 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]); reverse_adj[hashe[k2]].push_back(hashe[k1]); } if(n&1){ cout<<-1<<nli; return 0; } fip(1,n+1){ if(!vis[i]){ tptp = find_root(i); dfs(tptp,tptp); } } cout<<ans<<nli; // cerr << "Time elapsed : " << setprecision(6) << 100.00 * clock() / CLOCKS_PER_SEC << "ms\n"; }

Compilation message (stderr)

polygon.cpp: In function 'll find_root(ll)':
polygon.cpp:41:1: warning: control reaches end of non-void function [-Wreturn-type]
   41 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...