結果
| 問題 | No.3482 Quod Erat Demonstrandum |
| コンテスト | |
| ユーザー |
Kude
|
| 提出日時 | 2026-03-27 21:26:58 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 86 ms / 2,000 ms |
| コード長 | 1,946 bytes |
| 記録 | |
| コンパイル時間 | 2,488 ms |
| コンパイル使用メモリ | 360,140 KB |
| 実行使用メモリ | 17,488 KB |
| 最終ジャッジ日時 | 2026-03-27 21:27:12 |
| 合計ジャッジ時間 | 8,269 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 45 |
ソースコード
#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
vector<int> bfs(const vector<vector<int>>& g, int s=0) {
const int n = g.size();
vector<int> dist(n, -1);
vector<int> q(n);
q[0] = s;
dist[s] = 0;
int l = 0, r = 1;
while(l < r) {
int u = q[l++];
int nd = dist[u] + 1;
for(int v: g[u]) if (dist[v] == -1) {
dist[v] = nd;
q[r++] = v;
}
}
return dist;
}
} int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int tt;
cin >> tt;
while (tt--) {
int n, m;
cin >> n >> m;
VVI g(n);
vector<P> es;
rep(_, m) {
int a, b, c;
cin >> a >> b >> c;
a--, b--;
if (c == 1) {
g[a].emplace_back(b);
g[b].emplace_back(a);
} else {
es.emplace_back(a, b);
}
}
auto d1 = bfs(g, 0), d2 = bfs(g, n - 1);
if (d1[n-1] != -1) {
cout << "Same\n" << d1[n-1] << '\n';
} else {
constexpr int INF = 1001001001;
int ans = INF;
for (auto [a, b] : es) {
rep(_, 2) {
if (d1[a] != -1 && d2[b] != -1) chmin(ans, d1[a] + d2[b] + 1);
swap(a, b);
}
}
if (ans == INF) {
cout << "Unknown\n";
} else {
cout << "Different\n" << ans << '\n';
}
}
}
}
Kude