Editorial for Mạng Xã Hội


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
// Hello I'm Nekan
//
#include <bits/stdc++.h>
#define Nekan ""
#define fi first
#define se second
#define pb push_back
#define zs(v) ((int)(v).size())
#define BIT(x, i) (((x) >> (i)) & 1)
#define pii pair<int, int>

typedef long double ld;
typedef long long ll;

const int N = 1e5 + 5;
const long long mod = 1e9 + 7; /// 998244353

using namespace std;

void xuly() {
    int n; cin >> n;

    int current = 1;

    auto ask = [&](int u, int v) {
        cout << "? " << u << " " << v << endl;
        string x; cin >> x;
        return (x == "True!");
    };

    for (int i = 2; i <= n; ++i) {
        if (!ask(current, i)) {
            current = i;
        }
    }

    bool is_source = true;
    for (int i = 1; i <= n; ++i) {
        if (i == current) continue;
        if (!(ask(current, i) && !ask(i, current))) {
            is_source = false;
        }
    }

    cout << "! " << (is_source ? to_string(current) : "FRIENDLY") << endl;
}

int main() {
    // ios_base::sync_with_stdio(false);
    // cin.tie(0), cout.tie(0);
    if (fopen(Nekan ".inp", "r")) {
        freopen(Nekan ".inp", "r", stdin);
        freopen(Nekan ".out", "w", stdout);
    }
    int t; cin >> t;
    while(t--)
    xuly();
}

//Surely nothing could go wrong.

Comments

Please read the guidelines before commenting.


There are no comments at the moment.