Submission #977237

#TimeUsernameProblemLanguageResultExecution timeMemory
977237IsamLove Polygon (BOI18_polygon)C++17
0 / 100
167 ms33848 KiB
#include<bits/stdc++.h> using namespace std; #define eb emplace_back #define all(x) begin(x),end(x) constexpr int sz = 1e5 + 5; int n, tot, degree[sz]; string s1, s2; unordered_map<string, int> mp; unordered_map<int, bool> g[sz]; int k, ans; vector<int> st; bool vis[sz], mekni[sz]; bool cmp(int c, int d){ return degree[c] < degree[d]; } signed main(){ ios_base::sync_with_stdio(0), cin.tie(0); cin >> n; for(register int i = 1; i <= n; ++i) st.eb(i); for(register int i = 1; i <= n; ++i){ cin >> s1 >> s2; if(mp[s1] == 0) mp[s1] = ++tot; if(mp[s2] == 0) mp[s2] = ++tot; int u = mp[s1], v = mp[s2]; if(u == v) continue; degree[u]++, degree[v]++; g[u][v] = 1; if(g[v][u] == 1) ++k, mekni[v] = mekni[u] = vis[v] = vis[u] = 1; } sort(all(st), cmp); mp.clear(); if(n & 1) return cout << -1 << '\n', 0; set<int> obino; register int j(0); while(j < (int)st.size()){ if(mekni[st[j]]){ ++j; continue; } int u = st[j], v = -1; for(auto &to : g[u]){ if(vis[to.first] || to.second == false) continue; v = to.first; break; } if(v == -1){ obino.insert(u); mekni[u] = 1; continue; } vis[v] = 1; mekni[v] = 1; vis[u] = 1; ++ans; } int t(0); for(auto &to : obino){ if(vis[to]) continue; ++t; } ans += t; cout << ans << '\n'; return 0; } /* 1 2 +1 2 6 6 3 3 2 4 5 */

Compilation message (stderr)

polygon.cpp: In function 'int main()':
polygon.cpp:32:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   32 |  for(register int i = 1; i <= n; ++i) st.eb(i);
      |                   ^
polygon.cpp:34:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   34 |  for(register int i = 1; i <= n; ++i){
      |                   ^
polygon.cpp:60:15: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   60 |  register int j(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...