結果
| 問題 | No.3694 犬猿の仲 |
| コンテスト | |
| ユーザー |
itoito1234
|
| 提出日時 | 2026-09-09 21:50:26 |
| 言語 | C++23(gcc16) (gcc 16.1.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 30 ms / 2,000 ms |
| + 446µs | |
| コード長 | 1,412 bytes |
| 記録 | |
| コンパイル時間 | 4,642 ms |
| コンパイル使用メモリ | 390,080 KB |
| 実行使用メモリ | 15,148 KB |
| 最終ジャッジ日時 | 2026-09-09 21:50:34 |
| 合計ジャッジ時間 | 6,441 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge4_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 11 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define YES cout << "Yes" << endl;
#define NO cout << "No" << endl;
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
// using mint = modint998244353;
void solve() {
// ここに1テストケース分の処理を書く
int n,m;
cin>>n>>m;
vector<vector<int>>a(n);
rep(i,m){
int u,v;
cin>>u>>v;
a[u-1].push_back(v-1);
a[v-1].push_back(u-1);
}
vector<int>b(n,-1);
rep(i,n){
if(b[i]==-1){
b[i]=0;
queue<int>q;
q.push(i);
while(!q.empty()){
int x=q.front();
q.pop();
for(auto u:a[x]){
if(b[u]==b[x]){
NO
return;
}
else if(b[u]==-1){
b[u]=1^b[x];
q.push(u);
}
}
}
}
}
YES
}
int main() {
// 入出力の高速化
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin >> t; // テストケース数が最初に入力される問題の場合は、ここのコメントアウトを解除する
while (t--) {
solve();
}
}
itoito1234