結果
| 問題 |
No.1605 Matrix Shape
|
| コンテスト | |
| ユーザー |
momoyuu
|
| 提出日時 | 2023-11-18 04:25:36 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 51 ms / 2,000 ms |
| コード長 | 1,046 bytes |
| コンパイル時間 | 1,109 ms |
| コンパイル使用メモリ | 115,444 KB |
| 実行使用メモリ | 6,272 KB |
| 最終ジャッジ日時 | 2024-09-26 05:38:20 |
| 合計ジャッジ時間 | 4,495 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 34 |
ソースコード
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<cassert>
#include<set>
using namespace std;
using ll = long long;
#include<atcoder/dsu>
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n;
cin>>n;
atcoder::dsu uf(2<<17);
vector<int> use(2<<17,0),cnt(2<<17,0);
for(int i = 0;i<n;i++){
int h,w;
cin>>h>>w;
cnt[h]++;
cnt[w]--;
use[h] = 1;
use[w] = 1;
uf.merge(h,w);
}
set<int> s;
int a = 0;
int b = 0;
bool fn = true;
int ans = 0;
for(int i = 0;i<2<<17;i++){
if(use[i]==0) continue;
if(cnt[i]==1) a++;
if(cnt[i]==-1) b++;
ans++;
s.insert(uf.leader(i));
if(abs(cnt[i])>=2) fn = false;
}
if(s.size()>=2) fn = false;
if(!fn){
cout<<0<<endl;
return 0;
}
if(a==0&&b==0){
cout<<ans<<endl;
return 0;
}
if(a==1&&b==1){
cout<<1<<endl;
return 0;
}
cout<<0<<endl;
}
momoyuu