結果
| 問題 |
No.2664 Prime Sum
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-03-08 21:10:32 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 43 ms / 2,000 ms |
| コード長 | 1,001 bytes |
| コンパイル時間 | 2,129 ms |
| コンパイル使用メモリ | 203,716 KB |
| 最終ジャッジ日時 | 2025-02-20 01:57:25 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 37 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int N,M; cin >> N >> M;
vector<vector<int>> Graph(N);
for(int i=0; i<M; i++){
int u,v; cin >> u >> v;
u--; v--;
Graph.at(u).push_back(v);
Graph.at(v).push_back(u);
}
vector<int> dist(N,-1);
vector<bool> already(N);
bool yes = true;
for(int i=0; i<N; i++){
if(already.at(i)) continue;
dist.at(i) = 0;
queue<int> Q; Q.push(i);
while(Q.size()){
int pos = Q.front(); Q.pop();
already.at(pos) = true;
int nd = dist.at(pos)^1;
for(auto to : Graph.at(pos)){
if(dist.at(to) == -1){
dist.at(to) = nd;
Q.push(to);
}
else if(dist.at(to) != nd) yes = false;
}
}
}
if(yes) cout << "Yes" << endl;
else cout << "No" << endl;
}