結果
| 問題 | No.3482 Quod Erat Demonstrandum |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-10-07 09:31:27 |
| 言語 | C++23(gcc16) (gcc 16.1.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 144 ms / 2,000 ms |
| + 446µs | |
| コード長 | 1,239 bytes |
| 記録 | |
| コンパイル時間 | 2,861 ms |
| コンパイル使用メモリ | 207,876 KB |
| 実行使用メモリ | 18,352 KB |
| 最終ジャッジ日時 | 2026-10-07 09:31:44 |
| 合計ジャッジ時間 | 12,541 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 45 |
ソースコード
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
using ll = long long;
using P = pair<int, int>;
void solve(){
int n, m; cin >> n >> m;
vector<P> dif;
vector<vector<int>> to(n);
while(m--){
int a, b, c; cin >> a >> b >> c; a--, b--;
if(c==1){
to[a].push_back(b); swap(a, b);
to[a].push_back(b);
}
else dif.emplace_back(a, b);
}
auto BFS=[&](int st){
vector<int> ans(n, 1e9);
queue<P> bfs;
bfs.emplace(0, st);
ans[st]=0;
while(bfs.size()){
auto [d, now]=bfs.front(); bfs.pop();
if(ans[now]!=d) continue;
for(auto p:to[now]){
int nd=d+1;
if(ans[p]>nd){
ans[p]=nd;
bfs.emplace(nd, p);
}
}
}
return ans;
};
vector<int> dist1=BFS(0), dist2=BFS(n-1);
if(dist1[n-1]!=1e9){
cout << "Same" << '\n' << dist1[n-1] << '\n';
}
else{
int ans=1e9;
for(auto [u, v]:dif)for(int t=0; t<2; t++){
int now=dist1[u]+dist2[v]+1;
ans=min(ans, now);
swap(u, v);
}
if(ans!=1e9) cout << "Different" << '\n' << ans << '\n';
else cout << "Unknown" << '\n';
}
}
int main(void){
int t; cin >> t;
while(t--) solve();
return 0;
}