Submission #880844

#TimeUsernameProblemLanguageResultExecution timeMemory
880844vjudge1Love Polygon (BOI18_polygon)C++17
0 / 100
139 ms9736 KiB
// in the name of God #include<bits/stdc++.h> using namespace std; #define int long long #define fast() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define ff first #define ss second #define pb(x) push_back(x) #define all(x) x.begin(), x.end() #define mpp make_pair #define ppb pop_back #define endl '\n' #pragma GCC optimize("Ofast") #pragma GCC optimize("O4") #pragma GCC optimize("unroll-loops") //#pragma GCC target("avx2") mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int mod = 1e9 + 9, maxn = 1e5 + 10, inf = 1e9 + 1, lg = 25, pp = 4447, modd = 1e9 + 9; vector<int> out(maxn), c; bool mark[maxn]; map<string, int> mp; int n, pt, x, ans; void dfs(int v){ mark[v] = true; x++; if(!mark[out[v]]) dfs(out[v]); } signed main(){ fast(); cin >> n; for(int i = 0; i < n; ++i){ string a, b; cin >> a >> b; if(!mp[a]) mp[a] = ++pt; if(!mp[b]) mp[b] = ++pt; out[mp[a] - 1] = mp[b] - 1; } if(n % 2) return cout << -1, 0; for(int i = 0; i < pt; ++i){ if(!mark[i]){ x = 0; dfs(i); c.pb(x); } } for(int i : c){ if(i <= 2) continue; ans += ceil((double) i / 2); } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...