# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
716462 | Iliya | Love Polygon (BOI18_polygon) | C++17 | 227 ms | 14260 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define int long long
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
vector<int> Adj[N];
int n, ts, cnt;
map<string, int> MP;
vector<int> res;
bool Mark[N];
void DFS(int v) {
cnt++;
Mark[v] = true;
for (int u : Adj[v])
if (!Mark[u]) DFS(u);
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n;
for (int i = 0; i < n; i++) {
string s, t;
cin >> s >> t;
if (!MP[s]) MP[s] = ++ts;
if (!MP[t]) MP[t] = ++ts;
Adj[MP[s]].push_back(MP[t]);
}
for (int i = 1; i <= n; i++) {
if (!Mark[i]) {
cnt = 0;
DFS(i);
res.push_back(cnt);
}
}
if (n & 1)
return cout << "NO" << '\n', 0;
int odd = 0;
int ans = 0;
for (int x : res) {
ans += x / 2;
if (x & 1) odd;
}
ans += odd / 2;
cout << ans << '\n';
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |