結果
| 問題 |
No.2202 贅沢てりたまチキン
|
| ユーザー |
|
| 提出日時 | 2023-02-03 22:42:17 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,650 bytes |
| コンパイル時間 | 907 ms |
| コンパイル使用メモリ | 102,244 KB |
| 実行使用メモリ | 49,184 KB |
| 最終ジャッジ日時 | 2024-06-22 17:25:11 |
| 合計ジャッジ時間 | 6,308 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 20 TLE * 1 -- * 7 |
ソースコード
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.container.dlist;
class DisjointSet{
int[] parent;
this(int size){
parent = new int[size];
parent[] = -1;
}
void unite(int x, int y){
x = root(x);
y = root(y);
if(x == y) return;
if(parent[x] > parent[y]){
auto t = x;
x = y;
y = t;
}
parent[x] += parent[y];
parent[y] = x;
}
bool same(int x, int y){
return root(x) == root(y);
}
int root(int x){
if(parent[x] < 0) return x;
parent[x] = root(parent[x]);
return parent[x];
}
int size(int x){
return -parent[root(x)];
}
}
int N;
int M;
int[][] E;
void main(){
auto s = readln.chomp.split;
N = s[0].to!int;
M = s[1].to!int;
E = new int[][](N * 2);
auto ds = new DisjointSet(N);
for(auto m = 0; m < M; m++){
s = readln.chomp.split;
auto a = s[0].to!int - 1;
auto b = s[1].to!int - 1;
E[a] ~= b + N;
E[a + N] ~= b;
E[b] ~= a + N;
E[b + N] ~= a;
ds.unite(a, b);
}
auto result = true;
bool[int] results;
for(auto n = 0; n < N; n++){
if(ds.root(n) in results) continue;
auto r = dfs(n);
if(!r){
result = false;
break;
}
results[ds.root(n)] = true;
}
writeln(result ? "Yes" : "No");
}
bool dfs(int n){
auto q = DList!(Tuple!(int, int))();
q.insertBack(tuple(0, n));
auto used = new bool[N * 2];
while(!q.empty){
auto t = q.front;
q.removeFront;
if(t[0] % 2 == 1 && t[1] == n + N) return true;
if(used[t[1]]) continue;
used[t[1]] = true;
foreach(c; E[t[1]]){
if(used[c]) continue;
q.insertBack(tuple(t[0] + 1, c));
}
}
return false;
}