답안 #442516

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
442516 2021-07-08T05:40:21 Z abc864197532 Love Polygon (BOI18_polygon) C++17
0 / 100
259 ms 10680 KB
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define X first
#define Y second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define test(args...) abc("[" + string(#args) + "]", args)
void abc() {cerr << endl;}
template <typename T, typename ...U> void abc(T a, U ...b) {
    cerr << a << ' ', abc(b...);
}
template <typename T> void printv(T l, T r) {
    while (l != r) cerr << *l << " \n"[++l == r];
}
const int mod = 1e9 + 7, N = 200000;

int main () {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, _id = 0;
    cin >> n;
    map <string, int> m1;
    auto get = [&](string s) {
        if (m1.count(s)) return m1[s];
        return m1[s] = _id++;
    };
    vector <int> pt(n);
    string s, t;
    for (int i = 0; i < n; ++i) {
        cin >> s >> t;
        int u = get(s), v = get(t);
        pt[u] = v;
    }
    int ans = n;
    vector <bool> vis(n, false);
    for (int i = 0; i < n; ++i) if (!vis[i]) {
        int now = i, cur = 0;
        while (!vis[now]) {
            vis[now] = true;
            cur++;
            now = pt[now];
        }
        if (cur == 2) ans -= 2;
        else ans -= cur / 2;
    }
    cout << ans << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 244 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 204 ms 10680 KB Output is correct
5 Correct 233 ms 10592 KB Output is correct
6 Correct 257 ms 10680 KB Output is correct
7 Incorrect 208 ms 10608 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 259 ms 8460 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -