結果
問題 | No.483 マッチ並べ |
ユーザー |
|
提出日時 | 2020-08-14 01:24:11 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 863 bytes |
コンパイル時間 | 883 ms |
コンパイル使用メモリ | 64,896 KB |
最終ジャッジ日時 | 2025-01-12 22:14:42 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 53 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:29:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 29 | for(scanf("%d",&n);n--;){ | ~~~~~^~~~~~~~~ main.cpp:30:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 30 | scanf("%d%d%d%d",&a,&b,&c,&d); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <vector>#include <map>#include <set>#include <cstdio>using namespace std;template<typename T> class union_find{map<T,T> parent;public:T root(T a){if(parent.find(a)==parent.end())parent[a]=a;return parent[a]==a?a:(parent[a]=root(parent[a]));}int same(T a,T b){return root(a)==root(b);}int unite(T a,T b){T x=root(a),y=root(b);//if(x==y)return 0;parent[x]=y;return 1;}map<T,int> size(){map<T,int> r;for(auto &e:parent)r[root(e.first)]++;return r;}};int main(){union_find<pair<int,int>>uf;map<pair<int,int>,int>v;int n,a,b,c,d;for(scanf("%d",&n);n--;){scanf("%d%d%d%d",&a,&b,&c,&d);uf.unite({a,b},{c,d});v[{a,b}]++;}for(auto &e:v){auto r=uf.root(e.first);if(r!=e.first)v[r]+=e.second;}for(auto &e:uf.size()){if(e.second+1<=v[e.first]){puts("NO");return 0;}}puts("YES");}