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
using namespace std; struct node { int index,najmal_pat; node(int s,int p){ index = s; najmal_pat = p; } bool operator < (const node&tmp) const { return najmal_pat > tmp.najmal_pat; } }; int main() { int n,v; cin >> n >> v; vector
graph[15]; int niza[n]; for (int i = 0; i < n; i++) { cin >> niza[i]; graph[niza[i]].push_back(i); } priority_queue
pq; vector
visited (n+1, false); vector
portali(15, false); pq.push(node(0,0)); while(!pq.empty()){ node current = pq.top(); pq.pop(); visited[current.index] = true; if(current.index == n-1){ cout << current.najmal_pat; break; } if(!portali[niza[current.index]]) { for (int i = 0; i < graph[niza[current.index]].size(); i++) { int sosed = graph[niza[current.index]][i]; int pat = current.najmal_pat + v; if(!visited[sosed]) pq.push(node(sosed, pat)); } portali[niza[current.index]] = true; } if(current.index > 0 and !visited[current.index - 1]){ pq.push(node(current.index -1,current.najmal_pat +1)); } if(current.index < n and !visited[current.index + 1]){ pq.push(node(current.index +1,current.najmal_pat+1)); } } }
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)