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 index; double shortest_path; node(int i, double p){ index = i; shortest_path = p; } bool operator < (const node & tmp)const { return shortest_path > tmp.shortest_path; } }; int main() { int N; cin >> N; vector
> kordinati; for (int i = 0; i < N; i++) { int a,b; cin >> a >> b; kordinati.push_back(make_pair(a,b)); } vector
> graph [N]; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { double D = sqrt((kordinati[j].first - kordinati[i].first) * (kordinati[j].first - kordinati[i].first) + (kordinati[j].second - kordinati[i].second) * (kordinati[j].second - kordinati[i].second)); if (D<=10){ graph[i].push_back(make_pair(j,D)); graph[j].push_back(make_pair(i,D)); } } } priority_queue
pq; pq.push(node(0,0)); vector
vistited (N+1, false); vector
distance(N + 1, 2e9); distance[0] = 0; while (!pq.empty()){ node current = pq.top(); pq.pop(); vistited[current.index] = true; if(current.index == N-1){ cout << current.shortest_path << endl; break; } for (int i = 0; i < graph[current.index].size(); i++) { int sosed = graph[current.index][i].first; double path = graph[current.index][i].second; if(!vistited[sosed] and current.shortest_path + path < distance[sosed]){ pq.push(node(sosed,current.shortest_path + path)); distance[sosed] = current.shortest_path + path; } } } 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)