結果
| 問題 | No.3482 Quod Erat Demonstrandum |
| コンテスト | |
| ユーザー |
hiromi_ayase
|
| 提出日時 | 2026-03-27 21:51:25 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,604 bytes |
| 記録 | |
| コンパイル時間 | 4,437 ms |
| コンパイル使用メモリ | 382,084 KB |
| 実行使用メモリ | 20,852 KB |
| 最終ジャッジ日時 | 2026-03-27 21:51:47 |
| 合計ジャッジ時間 | 9,930 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 43 WA * 2 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
#define FAST_IO \
ios::sync_with_stdio(false); \
cin.tie(0);
const i64 INF = 1001001001001001001;
using Modint = atcoder::static_modint<998244353>;
int main() {
FAST_IO
int T;
cin >> T;
while (T--) {
int N, M;
cin >> N >> M;
vector<int> A(M), B(M), C(M);
for (int i = 0; i < M; i++) {
cin >> A[i] >> B[i] >> C[i];
A[i]--;
B[i]--;
}
vector<vector<pair<int, int>>> G(N);
for (int i = 0; i < M; i ++) {
G[A[i]].push_back({B[i], C[i]});
G[B[i]].push_back({A[i], C[i]});
}
int inf = 1e9;
vector<bool> ved(N * 2, false);
vector<int> d(N * 2, inf);
deque<int> q;
q.push_back(0);
ved[0] = true;
d[0] = 0;
while (q.size() > 0) {
auto cur = q.front();
q.pop_front();
int x = 0;
if (cur >= N) {
x = N;
}
for (auto [nex, c] : G[cur - x]) {
nex += x;
if (ved[nex]) continue;
if (d[nex] < d[cur] + 1) continue;
if (x > 0 && c == 2) continue;
if (c == 2) {
nex += N;
}
d[nex] = d[cur] + 1;
ved[nex] = true;
q.push_back(nex);
}
}
if (!ved[N-1] && !ved[N * 2 - 1]) {
cout << "Unknown" << endl;
} else if (ved[N-1]) {
cout << "Same" << endl;
cout << d[N-1] << endl;
} else {
cout << "Different" << endl;
cout << d[N*2-1] << endl;
}
}
}
hiromi_ayase