Submission #880938

# Submission time Handle Problem Language Result Execution time Memory
880938 2023-11-30T08:58:48 Z vjudge1 Love Polygon (BOI18_polygon) C++17
0 / 100
60 ms 27024 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long 
#define pb push_back
#define pii array<int, 2>

const int N = 1e5 + 4;

int m, out[N];
bool vis[N];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    vector<string> all;
    vector<array<string, 2>> edges;
    cin >> m;
    for (int i = 0; i < m; ++i) {
        string v, u;
        cin >> v >> u;
        edges.pb({v, u});
        all.pb(v);
        all.pb(u);
    }

    unordered_map<string, int> match;
    int last = 1;
    for (string s : all) {
        if (match[s] == 0) {
            match[s] = last++;
        }
    }

    for (auto [v, u] : edges) {
        out[match[v]] = match[u];
    }

    int ans = 0, odd = 0;
    for (int i = 1; i < last; ++i) {
        if (vis[i] == false) {
            int cur = i, cnt = 0;
            while (vis[cur] == false) {
                vis[cur] = true;
                cur = out[cur];
                ++cnt;
            }
            if (cnt != 2) {
                ans += cnt / 2;
                odd += cnt % 2;
            }
        }
    }

    if (odd % 2 == 1) {
        cout << -1;
    }
    else {
        cout << ans;
    }

    return 0;
}

# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 60 ms 27024 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -