Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
#include
#define pii pair
#define MAXN 100 const int INF = 1e9; using namespace std; vector
grafo[MAXN]; int dist[MAXN]; void bfs01(int s){ deque
q; q.push_front({0,s}); dist[s] = 0; while(!q.empty()){ pii e = q.front(); int v = e.second; q.pop_front(); for(pii viz : grafo[v]){ int u = viz.second; int w = viz.first; if(dist[v]+w < dist[u]){ dist[u] = dist[v]+w; if(w == 0){ q.push_front(viz); } else{ q.push_back(viz); } } } } } int main(){ int n, m; scanf("%d %d", &n, &m); for(int i = 0; i < m; i++){ int a, b, c; scanf("%d %d %d", &a, &b, &c); //aresta que liga a em b com custo c grafo[a].push_back({c, b}); grafo[b].push_back({c, a}); } for(int i = 0; i <= n; i++){ dist[i] = INF; } bfs01(1); printf("%d", dist[n]); }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)