Far Cities

Far Cities

确定树

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

bool query(int x, int y, int d) {
    cout << "? " << x << " " << y << " " << d << "\n";
    cout.flush();
    int q; cin >> q;
    return q == 0;
}

void solve() {
    int n; cin >> n;
    if(n == 2) {cout << "! 1 2 1" << endl; return;}
    int cur = 0, mx = -1;
    for(int i = 2; i <= n; i ++) {
        if(query(1, i, cur + 1)) continue;
        cur ++;
        while(!query(1, i, cur + 1)) cur ++;
        mx = i;
    }
    int md = 1;
    for(int i = 1; i <= n; i ++) {
        if(cur == n-1) break;
        if(i == mx) continue;
        if(query(mx, i, cur + 1)) continue;
        cur ++;
        while(!query(mx, i, cur + 1)) cur ++;
        md = i;
    }
    cout << "! " << md << " " << mx << " " << cur << endl;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int _=1; cin >> _;
    while(_--) solve();
    return 0;
}
posted @ 2026-10-11 21:02  thenrify  阅读(5)  评论(0)    收藏  举报