답안 #880959

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
880959 2023-11-30T09:14:21 Z vjudge1 Love Polygon (BOI18_polygon) C++17
25 / 100
82 ms 26516 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 + odd;
    }

    return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 64 ms 24932 KB Output is correct
5 Correct 71 ms 26516 KB Output is correct
6 Correct 68 ms 25404 KB Output is correct
7 Correct 82 ms 24032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 61 ms 22684 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -