結果
問題 | No.2202 贅沢てりたまチキン |
ユーザー |
![]() |
提出日時 | 2025-03-26 16:02:11 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 63 ms / 2,000 ms |
コード長 | 763 bytes |
コンパイル時間 | 3,140 ms |
コンパイル使用メモリ | 194,384 KB |
実行使用メモリ | 6,912 KB |
最終ジャッジ日時 | 2025-03-26 16:02:59 |
合計ジャッジ時間 | 5,606 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 28 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:36:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 36 | scanf("%d%d",&n,&m); | ~~~~~^~~~~~~~~~~~~~ main.cpp:40:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 40 | scanf("%d%d",&a,&b); | ~~~~~^~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>using namespace std;typedef long long ll;const int MAX=4e5+10;struct Disjoint_Set_Union{int pre[MAX],sz[MAX];void init(int n){int i;for(i=1;i<=n;i++){pre[i]=i;sz[i]=1;}}int find(int x){if(pre[x]!=x) pre[x]=find(pre[x]);return pre[x];}bool merge(int x,int y,bool dir=false){x=find(x);y=find(y);if(x==y) return 0;if(!dir && sz[x]>sz[y]) swap(x,y);pre[x]=y; // x -> ysz[y]+=sz[x];return 1;}}dsu;int main(){int n,m,i,a,b,ok;scanf("%d%d",&n,&m);dsu.init(2*n);while(m--){scanf("%d%d",&a,&b);dsu.merge(a,b+n);dsu.merge(a+n,b);}ok=1;for(i=1;i<=n;i++){if(dsu.find(i)!=dsu.find(i+n)) ok=0;}if(ok) puts("Yes");else puts("No");return 0;}