Блог пользователя Mahfuz2411

Автор Mahfuz2411, история, 5 часов назад, По-английски

Contest: Codeforces Round 967 (Div. 2) Problem: 2001C - Guess The Tree

Please read my post, and if you don't like it, before downvoting, please leave a comment explaining why you didn't like my post!

I haven't dealt with this type of problem before, so I don't know what's happening here. Please help me.

here is my code

void solve() {
    int n;   cin>>n;
    vector <int> v[1001];
    vector <pair <int,int>> ans;
    for(int i=2; i<=n; i++) {
        cout << "? " << 1 << ' ' << i << endl;
        cout.flush();
        int a;  cin>>a;
        if(a==1) ans.push_back({1, i});
        else v[a].push_back(i);
    }
 
    for(int i=2; i<=n; i++) {
        for(auto j: v[i]) {
            cout << "? " << i << ' ' << j << endl;
            cout.flush();
          
            int a;  cin>>a;
            if(a==-1) exit(0);
            if(a==i or a==j) ans.push_back({i, j});
            else v[a].push_back(j);
        }
    }
 
    cout << "! ";
    for(auto [x,y]: ans) cout << x << ' ' << y << spc;
    cout << newl;
    cout.flush();
    // long_line;
    return;
}

and here is my submission

  • Проголосовать: нравится
  • +2
  • Проголосовать: не нравится

»
5 часов назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

You may be asking more than the limit.

  • »
    »
    4 часа назад, # ^ |
      Проголосовать: нравится +3 Проголосовать: не нравится

    This is my only one post on this topic!!

    • »
      »
      »
      4 часа назад, # ^ |
        Проголосовать: нравится +3 Проголосовать: не нравится

      He meant that you may be taking more input than is given, so the program waits for input when nothing is left to input

    • »
      »
      »
      4 часа назад, # ^ |
        Проголосовать: нравится +3 Проголосовать: не нравится

      I mean, you're trying to solve this problem by asking the interactive machine too many times, so you're going to make mistakes.

      • »
        »
        »
        »
        4 часа назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        "They said that if more than 15n queries are made, the remaining queries will return -1. So, I added a logic where the program will terminate if -1 is received as input, and a wrong answer verdict will be given. So, this shouldn't be happening!

        • »
          »
          »
          »
          »
          4 часа назад, # ^ |
            Проголосовать: нравится 0 Проголосовать: не нравится

          When you receive -1, you are already wrong. Therefore, you need to keep the number of times strictly under 15n.

      • »
        »
        »
        »
        110 минут назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        so does this mean that if the logic of code is wrong then also idleness limit exceeded error can occur?

»
3 часа назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Idleness happens when the tester is waiting for your code to output something but nothing is happening. I recommend you to make you make your own test case and do a hard dry run on that. You can see my submissions on this question to see how I am so eligible to say so :|

»
67 минут назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Your solution is outputting less than n-1 edges, so the validator is wating for more edges to come but your program is waiting for an input from the validator (cin>>n)