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
#include
using namespace std; typedef long long ll; #define pb push_back #define mp make_pair #define f first #define s second vector
> graph[100005]; long long dist[100005]; bool visited[100005]; int main() { ios_base::sync_with_stdio(false); cout.tie(0); cin.tie(0); // ifstream cin("in.txt"); int n, m; cin >> n >> m; for(int i = 0; i < m; i++){ int a, b, c; cin >> a >> b >> c; graph[a-1].pb(mp(b-1, c)); } for(int i =0 ; i < n; i++) { dist[i] = 1e18; visited[i] = false; // sort(graph[i].begin(), graph[i].end(), [&](const pair
&a, const pair
&b) { // return a.second < b.second; // }); } set
> pq; dist[0] = 0; pq.insert(make_pair(0, 0)); while(!pq.empty()){ pair
c = *pq.begin(); pq.erase(pq.begin()); for(int i = 0; i < (int) graph[c.first].size(); i++){ int z = graph[c.first][i].f; if(c.second + graph[c.first][i].second < dist[z]) { pq.erase(make_pair(z, dist[z])); dist[z] = c.second + graph[c.first][i].second; pq.insert(make_pair(z, dist[z])); } } } for(int i = 0; i < n; i++){ cout << dist[i] << " "; } 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)