結果
| 問題 | No.3482 Quod Erat Demonstrandum |
| コンテスト | |
| ユーザー |
ZeriToki
|
| 提出日時 | 2026-03-27 22:53:40 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,430 bytes |
| 記録 | |
| コンパイル時間 | 3,549 ms |
| コンパイル使用メモリ | 342,464 KB |
| 実行使用メモリ | 20,056 KB |
| 最終ジャッジ日時 | 2026-03-27 22:53:58 |
| 合計ジャッジ時間 | 14,452 ms |
|
ジャッジサーバーID (参考情報) |
judge2_1 / judge3_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 23 WA * 22 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;}
const long long mod=998244353;
const long long mod2=469762049;
void solve(){
int N,M;cin>>N>>M;
int A[M+1],B[M+1],C[M+1];
vector<pair<int,int>>G[N+1];
for(int i=1;i<=M;i++){
cin>>A[i]>>B[i]>>C[i];
G[A[i]].push_back({C[i],B[i]});
G[B[i]].push_back({C[i],A[i]});
}
int dist[N+1];
bool already[N+1];
for(int i=1;i<=N;i++){
dist[i]=1e9;
already[i]=false;
}
deque<int>que;
que.push_front(1);
dist[1]=0;
while(!que.empty()){
int pos=que.front();
que.pop_front();
if(already[pos]) continue;
already[pos]=true;
for(auto nex:G[pos]){
if(nex.first==1){
if(dist[nex.second]>dist[pos]){
dist[nex.second]=dist[pos];
que.push_front(nex.second);
}
}
if(nex.first==2){
if(dist[nex.second]>dist[pos]+1){
dist[nex.second]=dist[pos]+1;
que.push_back(nex.second);
}
}
}
}
if(dist[N]==1e9){
cout<<"Unknown"<<endl;
return;
}
else if(dist[N]%2==1){
cout<<"Different"<<endl;
}
else{
cout<<"Same"<<endl;
}
for(int i=1;i<=N;i++){
dist[i]=1e9;
already[i]=false;
}
que.push_front(1);
dist[1]=0;
while(!que.empty()){
int pos=que.front();
que.pop_front();
if(already[pos]) continue;
already[pos]=true;
for(auto nex:G[pos]){
if(nex.first==1){
if(dist[nex.second]>dist[pos]+1){
dist[nex.second]=dist[pos]+1;
que.push_front(nex.second);
}
}
if(nex.first==2){
if(dist[nex.second]>dist[pos]+1){
dist[nex.second]=dist[pos]+1;
que.push_back(nex.second);
}
}
}
}
cout<<dist[N]<<endl;
}
int main(){
cin.tie(0)->sync_with_stdio(0);
cout.tie(0);
int T;cin>>T;
while(T--) solve();
}
ZeriToki