結果
| 問題 |
No.482 あなたの名は
|
| コンテスト | |
| ユーザー |
latte0119
|
| 提出日時 | 2017-02-10 23:22:01 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 33 ms / 2,000 ms |
| コード長 | 1,437 bytes |
| コンパイル時間 | 1,615 ms |
| コンパイル使用メモリ | 162,056 KB |
| 実行使用メモリ | 8,064 KB |
| 最終ジャッジ日時 | 2024-12-29 20:21:32 |
| 合計ジャッジ時間 | 3,077 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 28 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:51:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
51 | scanf("%lld%lld",&N,&K);
| ~~~~~^~~~~~~~~~~~~~~~~~
main.cpp:52:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
52 | rep(i,N)scanf("%lld",&D[i]),D[i]--;
| ~~~~~^~~~~~~~~~~~~~
ソースコード
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}
int N,K;
int D[222222];
struct UF{
vector<int>par,sz;
void init(int n){
par.resize(n);
sz.resize(n);
for(int i=0;i<n;i++){
par[i]=i;
sz[i]=1;
}
}
int find(int x){
return x==par[x]?x:par[x]=find(par[x]);
}
void unite(int x,int y){
x=find(x);y=find(y);
if(x==y)return;
sz[x]+=sz[y];
par[y]=x;
}
bool same(int x,int y){
return find(x)==find(y);
}
int size(int x){
return sz[find(x)];
}
};
signed main(){
scanf("%lld%lld",&N,&K);
rep(i,N)scanf("%lld",&D[i]),D[i]--;
UF uf;uf.init(N);
rep(i,N){
if(D[i]!=i)uf.unite(i,D[i]);
}
int cnt=0;
rep(i,N){
if(uf.find(i)!=i)continue;
cnt+=uf.size(i)-1;
}
if(cnt>K||(K-cnt)%2)cout<<"NO"<<endl;
else cout<<"YES"<<endl;
return 0;
}
latte0119