結果
問題 |
No.483 マッチ並べ
|
ユーザー |
![]() |
提出日時 | 2025-01-29 12:24:41 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 665 bytes |
コンパイル時間 | 2,231 ms |
コンパイル使用メモリ | 193,960 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2025-01-29 12:24:45 |
合計ジャッジ時間 | 4,118 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 53 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:14:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 14 | scanf("%d",&n); | ~~~~~^~~~~~~~~ main.cpp:17:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 17 | scanf("%d%d%d%d",&u1,&v1,&u2,&v2); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include<bits/stdc++.h> using namespace std; #define mk(x,y) ((x-1)*100+(y)) int fa[10005],cnt[10005],c2[10005]; int findfather(int x){ return x==fa[x]?x:fa[x]=findfather(fa[x]); } int main(){ int T=1; while(T--){ int N=10000; for(int i=1;i<=N;++i)fa[i]=i,cnt[i]=1,c2[i]=0; int n; scanf("%d",&n); for(int i=1;i<=n;++i){ int u1,v1,u2,v2; scanf("%d%d%d%d",&u1,&v1,&u2,&v2); int x=mk(u1,v1),y=mk(u2,v2); int fx=findfather(x),fy=findfather(y); if(fx!=fy){ fa[fx]=fy;cnt[fy]+=cnt[fx];c2[fy]+=c2[fx]; } ++c2[fy]; } int fl=1; for(int i=1;i<=N;++i)if(fa[i]==i){ if(c2[i]>cnt[i])fl=0; } puts(fl?"YES":"NO"); } return 0; }