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
#include
#include
#include
#include
using namespace std; struct node { int idx; int distance; node() {} node(int _idx, int _distance) { idx = _idx; distance = _distance; } bool operator < (const node &tmp) const { return distance > tmp.distance; } }; int main() { int n; // broj na teminja int m; // brojot na rebra cin >> n >> m; vector
> graph[n + 1]; for(int i = 0; i < m; i++) { int a, b, c; // povrzani se teminjata a i b so distanca c cin >> a >> b >> c; graph[a].push_back(make_pair(b, c)); graph[b].push_back(make_pair(a, c)); } int S, E; // S --> pocetno teme // E --> krajno teme cin >> S >> E; priority_queue
pq; pq.push(node(S, 0)); // prviot element vo priority queue bool visited[n + 1]; for(int i = 0; i < n; i++) { visited[i] = false; } while(!pq.empty()) { node c = pq.top(); pq.pop(); visited[c.idx] = true; if(c.idx == E) { cout << c.distance << endl; break; } for(int i = 0; i < graph[c.idx].size(); i++) { int sosed = graph[c.idx][i].first; int rebro = graph[c.idx][i].second; if(!visited[sosed]) { pq.push(node(sosed, c.distance + rebro)); } } } return 0; }
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)