結果
| 問題 | No.3695 同室と別室 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-09-09 21:43:25 |
| 言語 | PyPy3 (7.3.23 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 607 ms / 2,000 ms |
| + 170µs | |
| コード長 | 1,122 bytes |
| 記録 | |
| コンパイル時間 | 67 ms |
| コンパイル使用メモリ | 82,408 KB |
| 実行使用メモリ | 332,916 KB |
| 最終ジャッジ日時 | 2026-09-09 21:43:38 |
| 合計ジャッジ時間 | 3,996 ms |
|
ジャッジサーバーID (参考情報) |
judge4_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 13 |
ソースコード
import sys
from atcoder import dsu
from itertools import permutations
from bisect import bisect_left, bisect_right
import random
import math
from collections import deque
from collections import Counter
from collections import defaultdict
inf = 1 << 60
sys.setrecursionlimit(10**7)
def sgn(x):
if x > 0:
return 1
elif x == 0:
return 0
else:
return -1
def popC(x):
ans = 0
while x != 0:
ans += x % 2
x //= 2
return ans
def LI():
return list(map(int, input().split()))
def II():
return int(input())
def SI():
return input()
n, q = LI()
uf = dsu.DSU(n)
gr = [[] for _ in range(n)]
for _ in range(q):
t, a, b = LI()
a, b = a-1, b-1
uf.merge(a, b)
gr[a].append((b, t))
gr[b].append((a, t))
nowA = [-1] * n
def dfs(now, k):
if nowA[now] != -1:
return nowA[now] == k
nowA[now] = k
for to, t in gr[now]:
if not dfs(to, k ^ t):
return False
return True
for g in uf.groups():
if not dfs(g[0], 0):
print(0)
exit()
print(pow(2, len(uf.groups()), 998244353))