結果

問題 No.482 あなたの名は
ユーザー ukuku09ukuku09
提出日時 2017-02-11 01:15:45
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 1,205 bytes
コンパイル時間 1,182 ms
コンパイル使用メモリ 147,476 KB
実行使用メモリ 6,372 KB
最終ジャッジ日時 2023-08-28 16:18:32
合計ジャッジ時間 3,138 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 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,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 26 ms
6,212 KB
testcase_16 AC 27 ms
6,144 KB
testcase_17 AC 27 ms
6,216 KB
testcase_18 AC 27 ms
6,340 KB
testcase_19 AC 25 ms
6,240 KB
testcase_20 AC 25 ms
6,372 KB
testcase_21 AC 25 ms
6,232 KB
testcase_22 AC 25 ms
6,240 KB
testcase_23 AC 24 ms
6,196 KB
testcase_24 AC 24 ms
6,192 KB
testcase_25 AC 24 ms
6,216 KB
testcase_26 AC 24 ms
6,260 KB
testcase_27 AC 24 ms
6,128 KB
testcase_28 AC 25 ms
6,216 KB
testcase_29 AC 22 ms
6,244 KB
testcase_30 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

struct UnionFind {
  vector<int> data;
  UnionFind(){}
  UnionFind(int n):data(n, -1){}
  int find(int x){ return (data[x] < 0 ? x : data[x] = find(data[x])); }
  int size(int x){ return -data[find(x)]; }
  bool same(int x, int y) { return find(x) == find(y); }
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return false;
    if(data[x] < data[y]) swap(x, y);
    data[x] += data[y], data[y] = x;
    return true;
  }
};

#define MAX_N 200000
int N, K;
int D[MAX_N];
UnionFind uf;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  cin >> N >> K;
  uf = UnionFind(N);
  rep(i, N) cin >> D[i], uf.unite(i, --D[i]);

  int sum = 0;
  rep(i, N) if(i == uf.find(i)) sum += uf.size(i)-1;

  if(sum > K) puts("NO");
  else if((K - sum) % 2) puts("NO");
  else puts("YES");

  return 0;
}
0