Answer the question
In order to leave comments, you need to log in
How to read data from standard stream faster?
Kind time of day:) Help the beginner
I write topological sorting.
In one of the tests, the time limit is 3 seconds, the number of graphs is 1000 and 500 edges (respectively, also 500 pairs of numbers indicating the beginning and end of the edge).
For sorting, I use the adjacency matrix matr, into which I write 1 if there is such an edge from the i -th edge to the j -th. Reading i and j takes a whole 7 seconds :-( I can’t think of a better option. Can I replace scanf with something?
Here is a piece of code:
int** readbond( int** matr)
{
int i, j;
while (scanf("%d%d", &i, &j))
{
matr[i ][j] = 1;
}
return matr;
}
Answer the question
In order to leave comments, you need to log in
habrahabr.ru/post/246257
Here is mainly for C ++, but the 6th option should work for C.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question