結果
| 問題 | No.3482 Quod Erat Demonstrandum |
| コンテスト | |
| ユーザー |
Tehom
|
| 提出日時 | 2026-03-31 15:12:32 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 68 ms / 2,000 ms |
| コード長 | 1,697 bytes |
| 記録 | |
| コンパイル時間 | 3,265 ms |
| コンパイル使用メモリ | 279,048 KB |
| 実行使用メモリ | 22,296 KB |
| 最終ジャッジ日時 | 2026-03-31 15:13:40 |
| 合計ジャッジ時間 | 7,896 ms |
|
ジャッジサーバーID (参考情報) |
judge2_1 / judge3_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 45 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define ll long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define repl(i,a,b) for(ll i=(a);i<(b);i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
template <typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;} return false;}
template <typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;} return false;}
void solve(){
int n,m; cin >> n >> m;
vector<vector<int>> eq(n),neq(n);
rep(i,0,m){
int a,b,c; cin >> a >> b >> c;
a--,b--;
if(c == 1){
eq[a].push_back(b);
eq[b].push_back(a);
}
else{
neq[a].push_back(b);
neq[b].push_back(a);
}
}
int INF=1e9;
vector<int> dist(n,INF);
queue<int> que;
que.push(0);
dist[0]=0;
while(!que.empty()){
auto v=que.front();
que.pop();
for(auto nv:eq[v]){
if(dist[nv] != INF) continue;
dist[nv]=dist[v]+1;
que.push(nv);
}
}
if(dist[n-1] != INF){
cout << "Same" << "\n";
cout << dist[n-1] << "\n";
return;
}
int ans=INF;
vector<int> dist2(n,INF);
dist2[n-1]=0;
que.push(n-1);
while(!que.empty()){
auto v=que.front();
que.pop();
for(auto nv:eq[v]){
if(dist2[nv] != INF) continue;
dist2[nv]=dist2[v]+1;
que.push(nv);
}
for(auto nv:neq[v]){
if(dist[nv] != INF){
chmin(ans,dist[nv]+dist2[v]+1);
}
}
}
if(ans != INF){
cout << "Different" << "\n";
cout << ans << "\n";
}
else cout << "Unknown" << "\n";
return;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T; cin >> T;
while(T--) solve();
}
Tehom