trunghieu11's blog

By trunghieu11, history, 9 years ago, In English

As I know one of ways for storing a weighted graph is using Adjacency List but cons of this solution is when we want to get weight of a pair vertex this will cost O(n) by looping the adjacency vertex.

So I have a solution to improve that by using Map<NodeID, Map<NodeID, Weight>> then when we want to get weight of a pair vertex, for example (1, 2) we just call Node[1].get(Node[2]), this only cost O(1).

Is this correct? I'm using Java so can it have a risk?

Full text and comments »

  • Vote: I like it
  • -3
  • Vote: I do not like it

By trunghieu11, 10 years ago, In English

Is there any ways we can update Binary Index Tree when it's a min/max tree?

For example, I have an array:

10 4 5 6 8

tree.getMin(3) = 4; //query at index 3 the result is 4

tree.update(2, 1); //update value at index 2 from 5 to 1

tree.getMin(3) = 1; //requery at index 3 we have the new result is 1

Thanks!!

Full text and comments »

  • Vote: I like it
  • -8
  • Vote: I do not like it

By trunghieu11, 12 years ago, In English

In problem http://codeforces.me/contest/296/problem/C I try to create a test for hacking, but I get error "Invalid input". I don't know why my code get this error. Please help me, here's my code:

int main() {
    cout << "100000 100000 100000\n";
    for (int i = 0; i < 100000; i++) {
        if (i)
            cout << " ";
        cout << "100000";
    }
    cout << "\n";
    for (int i = 0; i < 100000; i++) {
        if (i)
            cout << "\n";
        cout << "1 100000 100000";
    }
    cout << "\n";
    for (int i = 0; i < 100000; i++) {
        if (i)
            cout << "\n";
        cout << "1 100000";
    }
    cout << "\n";
}

Full text and comments »

  • Vote: I like it
  • +5
  • Vote: I do not like it

By trunghieu11, 12 years ago, In English

In problem http://codeforces.me/contest/296/problem/C I try to create a test for hacking, but I get error "Invalid input". I don't know why my code get this error. Please help me, here's my code:

int main() {
    cout << "100000 100000 100000\n";
    for (int i = 0; i < 100000; i++) {
        if (i)
            cout << " ";
        cout << "100000";
    }
    cout << "\n";
    for (int i = 0; i < 100000; i++) {
        if (i)
            cout << "\n";
        cout << "1 100000 100000";
    }
    cout << "\n";
    for (int i = 0; i < 100000; i++) {
        if (i)
            cout << "\n";
        cout << "1 100000";
    }
    cout << "\n";
}

Full text and comments »

  • Vote: I like it
  • -3
  • Vote: I do not like it

By trunghieu11, 12 years ago, In English

Somebody can tell me how to see friend's rating? Thanks so much :D

Full text and comments »

  • Vote: I like it
  • +5
  • Vote: I do not like it