ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1930. Ivan's Car

Befor using bfs...
Posted by NUUZ_1 31 Oct 2012 13:27
How can I quickly build adjacency matrix befor using bfs for this problem. I have TLE#6,#10,#12 for this problem. Any algorithm please!
Re: Befor using bfs...
Posted by bsu.mmf.team 1 Nov 2012 18:32
Adjancency matrix will require 10000^2 elements. It's too many, u won't fit in memory limit.
Use adjancency list instead. For example, if you use C++, you can represent it as an array of vectors, where the vector at index i contains numbers of vertices that adjanced to the vertex with number i.
for (int i=0; i<N; i++) {
int a, b;
cin >> a >> b;
vect[a].push_back(b);
vect[b].push_back(a);
}
Re: Befor using bfs...
Posted by alexProgrammer 2 Nov 2012 19:25
ok, there are vectors.
but how insert this vectors to the Deikstra algorithm?