結果

問題 No.482 あなたの名は
ユーザー tubo28tubo28
提出日時 2017-02-10 22:36:04
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 66 ms / 2,000 ms
コード長 1,952 bytes
コンパイル時間 1,785 ms
コンパイル使用メモリ 174,732 KB
実行使用メモリ 5,632 KB
最終ジャッジ日時 2023-08-28 15:43:31
合計ジャッジ時間 4,299 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 64 ms
5,484 KB
testcase_16 AC 64 ms
5,348 KB
testcase_17 AC 63 ms
5,492 KB
testcase_18 AC 63 ms
5,372 KB
testcase_19 AC 63 ms
5,348 KB
testcase_20 AC 64 ms
5,416 KB
testcase_21 AC 66 ms
5,348 KB
testcase_22 AC 63 ms
5,524 KB
testcase_23 AC 65 ms
5,304 KB
testcase_24 AC 65 ms
5,304 KB
testcase_25 AC 64 ms
5,348 KB
testcase_26 AC 64 ms
5,468 KB
testcase_27 AC 64 ms
5,632 KB
testcase_28 AC 64 ms
5,416 KB
testcase_29 AC 59 ms
5,368 KB
testcase_30 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b) - 1; i >= int(a); --i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, int(n) + 1)
#define rrep(i, n) RFOR(i, 0, n)
#define rrep1(i, n) RFOR(i, 1, int(n) + 1)
#define all(c) begin(c), end(c)
template<typename T> void __dump__(const T &first){ std::cerr << first << std::endl; }
template<typename First, typename... Rest>
void __dump__(const First& first, const Rest&... rest) { std::cerr << first << ", "; __dump__(rest...); }
#define dump(...) { std::cerr << __LINE__ << ":\t" #__VA_ARGS__ " = "; __dump__(__VA_ARGS__); }


struct uf_tree {
    std::vector<int> parent;
    int __size;
    uf_tree(int size_) : parent(size_, -1), __size(size_) {}
    void unite(int x, int y) {
        if ((x = find(x)) != (y = find(y))) {
            if (parent[y] < parent[x]) std::swap(x, y);
            parent[x] += parent[y];
            parent[y] = x;
            __size--;
        }
    }
    bool is_same(int x, int y) { return find(x) == find(y); }
    int find(int x) { return parent[x] < 0 ? x : parent[x] = find(parent[x]); }
    int size(int x) { return -parent[find(x)]; }
    int size() { return __size; }
};

#define int ll

int a[200010];

signed main(){
    int n, k;
    while(cin >> n >> k){
        uf_tree uf(n);
        rep(i, n){
            cin >> a[i];
            --a[i];
            uf.unite(i, a[i]);
        }
        map<int, int> cnt;
        rep(i, n){
            int r = uf.find(i);
            ++cnt[uf.size(r)];
        }
        int sw = 0;
        for(auto &x : cnt){
            int g = x.second / x.first;
            int k = g * (x.first - 1);
            // dump(x.first, x.second, k);
            sw += k;
        }
        if(sw > k){
            puts("NO");
        } else {
            puts((k - sw) % 2 == 0 ? "YES" : "NO");
        }
    }
}
0