結果
| 問題 |
No.2664 Prime Sum
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-03-08 21:37:38 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 59 ms / 2,000 ms |
| コード長 | 644 bytes |
| コンパイル時間 | 1,943 ms |
| コンパイル使用メモリ | 200,572 KB |
| 最終ジャッジ日時 | 2025-02-20 02:16:19 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 37 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
bool dfs(const vector<set<int>>& G, int v, vector<int>& V){
for(int u:G[v]){
if(V[u]==V[v]){
return false;
}else{
if(!V[u]){
V[u]=5-V[v];
bool b=dfs(G,u,V);
if(!b){
return false;
}
}
}
}
return true;
}
int main(){
int n,m;
cin >> n >> m;
vector<set<int>> G(n);
for(int j=0;j<m;j++){
int a,b;
cin >> a >> b;
a--;
b--;
G[a].insert(b);
G[b].insert(a);
}
vector<int> V(n,0);
bool b=true;
for(int i=0;i<n;i++){
if(!V[i]){
V[i]=2;
b=dfs(G,i,V);
if(!b){
break;
}
}
}
cout << (b?"Yes":"No") << endl;
return EXIT_SUCCESS;
}