結果
| 問題 |
No.1601 With Animals into Institute
|
| コンテスト | |
| ユーザー |
沙耶花
|
| 提出日時 | 2021-07-10 14:05:44 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 584 ms / 3,000 ms |
| コード長 | 1,082 bytes |
| コンパイル時間 | 6,005 ms |
| コンパイル使用メモリ | 255,752 KB |
| 最終ジャッジ日時 | 2025-01-23 00:02:47 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 36 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:19:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
19 | scanf("%lld %lld %lld %lld",&A[i],&B[i],&C[i],&D[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint1000000007;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000000000000000
int main(){
int N,M;
cin>>N>>M;
vector<long long> A(M),B(M),C(M),D(M);
vector<vector<int>> E(N);
rep(i,M){
scanf("%lld %lld %lld %lld",&A[i],&B[i],&C[i],&D[i]);
A[i]--;B[i]--;
E[A[i]].push_back(i);
E[B[i]].push_back(i);
}
vector<long long> dis(N*2,Inf);
priority_queue<pair<long long,int>,vector<pair<long long,int>>,greater<pair<long long,int>>> Q;
dis[N*2-1] = 0LL;
Q.emplace(0,N*2-1);
while(Q.size()>0){
long long DD = Q.top().first;
int u = Q.top().second/2,x = Q.top().second%2;
Q.pop();
if(DD != dis[u*2+x])continue;
rep(i,E[u].size()){
int ind = E[u][i];
int v = A[ind] ^ B[ind] ^ u;
int nx = x;
if(D[ind])nx = 0;
long long D2 = DD + C[ind];
int temp = v*2 + nx;
if(dis[temp]>D2){
dis[temp] = D2;
Q.emplace(D2,temp);
}
}
}
rep(i,N-1){
cout<<dis[i*2]<<endl;
}
return 0;
}
沙耶花