이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/**
* Solution by 1egend (polarity.sh)
* Date: 2024-11-13
* Contest: CSES Problemset - Graph Algorithms
* Problem: 1202
**/
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ull unsigned long long
#define ll long long
const int MAX_N = 1e5 + 1;
const ll MOD = 1e9 + 7;
void solve(){
int n, m; cin >> n >> m;
vector<ll> dist(n, 1e15);
map<pair<int, int>, int> multiple;
vector<vector<tuple<int, int, ll>>> adj(n);
for (int i = 0; i < m; i++){
int a, b, c; cin >> a >> b >> c;
--a; --b; --c;
ll d; cin >> d;
multiple[{a, c}]++;
multiple[{b, c}]++;
adj[a].pb({b, c, d});
adj[b].pb({a, c, d});
}
using T = tuple<ll, int, int>;
priority_queue<T, vector<T>, greater<T>> pq;
dist[0] = 0;
pq.push({0LL, 0, -1});
while(!pq.empty()){
auto [ndist, k, c] = pq.top();
pq.pop();
if (ndist != dist[k]) { continue; }
for (tuple<int, int, ll> &node: adj[k]){
int kk = get<0>(node);
int color = get<1>(node);
ll cost = get<2>(node);
if (multiple[{k, color}] == 1 || multiple[{k, color}] == 2 && c == color){
cost = 0;
}
if (ndist + cost < dist[kk]){
dist[kk] = ndist + cost;
pq.push({dist[kk], kk, color});
}
}
}
cout << (dist[n - 1] == 1e15 ? -1: dist[n - 1])<< endl;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'void solve()':
Main.cpp:52:72: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
52 | if (multiple[{k, color}] == 1 || multiple[{k, color}] == 2 && c == color){
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |