Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

You're putting too much effort into your input reading. Just use cin it'll be fast enough. The problem is in your algorithm, not the input parsing. The note about input size on the site is meant for languages where naive handling of input can be slow, e.g. Java. C++ is not affected by this.

Instead of implementing your own hash function you can use std::hash (since C++11). Or simply use std::unordered_map which is basically a hash map, and save yourself a lot of trouble.

Your naming of types and variables is absolutely horrific. Use descriptive names, a type called ii is not descriptive.

Macros are evil Macros are evil don't use them like that.

Now to the core of your problem. You're applying Dijkstra's algorithm for each of the queries in the test case. This is where your slow down is.

You need to use the Floyd-Warshall Algorithm. This will bring down your run-time and make you get past the TLE with flying colours.

You're putting too much effort into your input reading. Just use cin it'll be fast enough. The problem is in your algorithm, not the input parsing. The note about input size on the site is meant for languages where naive handling of input can be slow, e.g. Java. C++ is not affected by this.

Instead of implementing your own hash function you can use std::hash (since C++11). Or simply use std::unordered_map which is basically a hash map, and save yourself a lot of trouble.

Your naming of types and variables is absolutely horrific. Use descriptive names, a type called ii is not descriptive.

Macros are evil don't use them like that.

Now to the core of your problem. You're applying Dijkstra's algorithm for each of the queries in the test case. This is where your slow down is.

You need to use the Floyd-Warshall Algorithm. This will bring down your run-time and make you get past the TLE with flying colours.

You're putting too much effort into your input reading. Just use cin it'll be fast enough. The problem is in your algorithm, not the input parsing. The note about input size on the site is meant for languages where naive handling of input can be slow, e.g. Java. C++ is not affected by this.

Instead of implementing your own hash function you can use std::hash (since C++11). Or simply use std::unordered_map which is basically a hash map, and save yourself a lot of trouble.

Your naming of types and variables is absolutely horrific. Use descriptive names, a type called ii is not descriptive.

Macros are evil don't use them like that.

Now to the core of your problem. You're applying Dijkstra's algorithm for each of the queries in the test case. This is where your slow down is.

You need to use the Floyd-Warshall Algorithm. This will bring down your run-time and make you get past the TLE with flying colours.

added 155 characters in body
Source Link
Emily L.
  • 16.7k
  • 1
  • 39
  • 89

You're putting too much effort into your input reading. Just use cin it'll be fast enough. The problem is in your algorithm, not the input parsing. The note about input size on the site is meant for languages where naive handling of input can be slow, e.g. Java. C++ is not affected by this.

Instead of implementing your own hash function you can use std::hash (since C++11). Or simply use std::unordered_map which is basically a hash map, and save yourself a lot of trouble.

Your naming of types and variables is absolutely horrific. Use descriptive names, a type called ii is not descriptive.

Macros are evil don't use them like that.

Now to the core of your problem. You're applying Dijkstra's algorithm for each of the queries in the test case. This is where your slow down is.

You need to use the Floyd-Warshall Algorithm. This will bring down your run-time and make you get past the TLE with flying colours.

You're putting too much effort into your input reading. Just use cin it'll be fast enough. The problem is in your algorithm, not the input parsing. The note about input size on the site is meant for languages where naive handling of input can be slow, e.g. Java. C++ is not affected by this.

Instead of implementing your own hash function you can use std::hash (since C++11). Or simply use std::unordered_map which is basically a hash map, and save yourself a lot of trouble.

Your naming of types and variables is absolutely horrific. Use descriptive names, a type called ii is not descriptive.

Now to the core of your problem. You're applying Dijkstra's algorithm for each of the queries in the test case. This is where your slow down is.

You need to use the Floyd-Warshall Algorithm. This will bring down your run-time and make you get past the TLE with flying colours.

You're putting too much effort into your input reading. Just use cin it'll be fast enough. The problem is in your algorithm, not the input parsing. The note about input size on the site is meant for languages where naive handling of input can be slow, e.g. Java. C++ is not affected by this.

Instead of implementing your own hash function you can use std::hash (since C++11). Or simply use std::unordered_map which is basically a hash map, and save yourself a lot of trouble.

Your naming of types and variables is absolutely horrific. Use descriptive names, a type called ii is not descriptive.

Macros are evil don't use them like that.

Now to the core of your problem. You're applying Dijkstra's algorithm for each of the queries in the test case. This is where your slow down is.

You need to use the Floyd-Warshall Algorithm. This will bring down your run-time and make you get past the TLE with flying colours.

Source Link
Emily L.
  • 16.7k
  • 1
  • 39
  • 89

You're putting too much effort into your input reading. Just use cin it'll be fast enough. The problem is in your algorithm, not the input parsing. The note about input size on the site is meant for languages where naive handling of input can be slow, e.g. Java. C++ is not affected by this.

Instead of implementing your own hash function you can use std::hash (since C++11). Or simply use std::unordered_map which is basically a hash map, and save yourself a lot of trouble.

Your naming of types and variables is absolutely horrific. Use descriptive names, a type called ii is not descriptive.

Now to the core of your problem. You're applying Dijkstra's algorithm for each of the queries in the test case. This is where your slow down is.

You need to use the Floyd-Warshall Algorithm. This will bring down your run-time and make you get past the TLE with flying colours.

lang-cpp

AltStyle によって変換されたページ (->オリジナル) /