結果
| 問題 |
No.1605 Matrix Shape
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-07-16 21:36:41 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 124 ms / 2,000 ms |
| コード長 | 733 bytes |
| コンパイル時間 | 652 ms |
| コンパイル使用メモリ | 75,312 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-06 08:34:11 |
| 合計ジャッジ時間 | 3,974 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 34 |
コンパイルメッセージ
main.cpp:7:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
7 | main()
| ^~~~
ソースコード
#include<iostream>
#include<atcoder/dsu>
using namespace std;
int N;
int deg[2<<17];
bool vis[2<<17];
main()
{
cin>>N;
atcoder::dsu P(2<<17);
for(int i=0;i<N;i++)
{
int u,v;cin>>u>>v;u--,v--;
deg[u]++;
deg[v]--;
vis[u]=vis[v]=true;
P.merge(u,v);
}
int f=-1;
bool fs=false,fg=false;
int cnt=0;
for(int i=0;i<2<<17;i++)if(vis[i])
{
cnt++;
if(deg[i]==0);
else if(deg[i]==1)
{
if(fs)
{
cout<<0<<endl;
return 0;
}
fs=true;
}
else if(deg[i]==-1)
{
if(fg)
{
cout<<0<<endl;
return 0;
}
fg=true;
}
else
{
cout<<0<<endl;
return 0;
}
int t=P.leader(i);
if(f==-1)f=t;
else if(f!=t)
{
cout<<0<<endl;
return 0;
}
}
cout<<(fs?1:cnt)<<endl;
}