結果
| 問題 |
No.2202 贅沢てりたまチキン
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-20 21:19:59 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 61 ms / 2,000 ms |
| コード長 | 763 bytes |
| コンパイル時間 | 4,792 ms |
| コンパイル使用メモリ | 194,936 KB |
| 実行使用メモリ | 7,324 KB |
| 最終ジャッジ日時 | 2025-03-20 21:21:04 |
| 合計ジャッジ時間 | 4,268 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / 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 -> y
sz[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;
}
lam6er