답안 #712069

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
712069 2023-03-18T04:28:59 Z wenqi Love Polygon (BOI18_polygon) C++17
0 / 100
72 ms 19612 KB
// trans rights
#include <bits/extc++.h>
using namespace std;
using ll = long long;

int N;
unordered_map<string, int> mp;

int to[100069];
int cnt[100069];
bool taken[100069];

int main(int argc, const char *argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> N;
    if (N & 1)
    {
        cout << -1;
        return 0;
    }
    int n = 1;
    for (int i = 0; i < N; i++)
    {
        string a, b;
        cin >> a >> b;
        int ia = mp[a], ib = mp[b];
        if (not ia)
            ia = mp[a] = n++;
        if (not ib)
            ib = mp[b] = n++;
        to[ia] = ib;
        cnt[ib]++;
    }
    priority_queue<pair<int, int>> pq;
    for (int i = 1; i <= N; i++)
    {
        if (i == to[to[i]])
        {
            taken[i] = true;
            taken[to[i]] = true;
        }
    }
    for (int i = 1; i <= N; i++)
    {
        if (not taken[i])
            pq.push({-cnt[i], i});
    }
    int ans = 0;
    while (pq.size())
    {
        auto [k, i] = pq.top();
        pq.pop();
        if (-k != cnt[i] or taken[i])
            continue;
        ans++;
        if (taken[to[i]])
        {
            continue;
        }
        cnt[to[to[i]]]--;
        pq.push({-cnt[to[to[i]]], to[to[i]]});
        taken[i] = taken[to[i]] = true;
    }
    cout << ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Incorrect 1 ms 340 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 72 ms 19612 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Incorrect 1 ms 340 KB Output isn't correct
8 Halted 0 ms 0 KB -