답안 #1026901

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1026901 2024-07-18T13:20:40 Z 12345678 Love Polygon (BOI18_polygon) C++17
0 / 100
208 ms 15308 KB
#include <bits/stdc++.h>

using namespace std;

const int nx=1e5+5;

int n, t, vs[nx], l[nx], res, cnt, lv[nx];
string su[nx], sv[nx];
map<string, int> mp;

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n;
    for (int i=1; i<=n; i++) cin>>su[i]>>sv[i], mp[su[i]]=mp[sv[i]]=0;
    if (n%2) return cout<<-1, 0;
    for (auto &[x, y]:mp) y=++t;
    for (int i=1; i<=n; i++) 
    {
        l[mp[su[i]]]=mp[sv[i]];
        if (mp[su[i]]!=mp[sv[i]]) lv[mp[sv[i]]]=1;
    }
    for (int i=1; i<=n; i++)
    {
        if (lv[i]) continue;
        int sz=1, tmp=i;
        while (l[tmp]!=tmp) sz++, tmp=l[tmp];
        //cout<<"debug "<<i<<' '<<sz<<'\n';
        res+=sz/2;
        if (sz%2) res++;
    }
    cout<<res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Incorrect 1 ms 6748 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Incorrect 1 ms 6748 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 208 ms 15308 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Incorrect 1 ms 6748 KB Output isn't correct
4 Halted 0 ms 0 KB -