Robin's blog

By Robin, history, 4 months ago, In English,

So I was debugging this code and managed input/outputs in separate files. I ran the same code with same flags in codeblocks and WSL ubuntu 18.04, they gave me two different outputs.

My Code

#include<bits/stdc++.h>

using namespace std;

int main() {
#ifdef ROBIN
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif // ROBIN
    int t, d = 0;
    cin >> t;
    getchar();
    while (t--) {
        string ss, tt;
        getline(cin, ss);
        getline(cin, tt);
        cout << "SS: " << ss << endl;
        cout << "TT: " << tt << endl;
    }
}

Input

3
Tom Marvolo Riddle
I am Lord Voldemort
I am not Harry Potter
Hi Pretty Roar to man
Harry and Voldemort
Tom and Jerry and Harry

Output (Code::Blocks)

SS: Tom Marvolo Riddle
TT: I am Lord Voldemort
SS: I am not Harry Potter
TT: Hi Pretty Roar to man
SS: Harry and Voldemort
TT: Tom and Jerry and Harry

Output (WSL)

SS: 
TT: Tom Marvolo Riddle
SS: I am Lord Voldemort
TT: I am not Harry Potter
SS: Hi Pretty Roar to man
TT: Harry and Voldemort



I would appreciate it if someone gives me a proper explanation of this. Thanks.
Flags:
-DROBIN
-std=c++14
-O2

Read more »

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

By Robin, history, 8 months ago, In English,

Hello CF! How do I calculate 2nd best MST? Is removing the shortest edge in the 1st MST from the original graph and calculating MST again would be enough? Also, how do I calculate n'th best MST in general?

Read more »

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

By Robin, history, 11 months ago, In English,

Need help with this problem:

https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=&problem=6218

My solution: https://paste.ubuntu.com/p/tfhFWN8hZj/

Verdict: TLE

I used Sparse Table for the LCA and Kruskal for the MST. My actual code starts from line 117, the rest above is template, can be ignored. I commented in each step to explain what I did.

My idea for the solution: I construct MST from the given graph. This way I only repair the roads that yield minimum cost and connects all the cities. Then, for each query, if the given road is already in the MST, we just construct the rest of the roads in the MST. Hence we return the sum of all edges in the MST. Else, if the road is not in the MST, we remove the most costly road (largest weighted edge) along the path from u to v from the MST, and add the given road.

What did I do wrong?

Read more »

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