1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
#include <bits/stdc++.h> using namespace std; template <typename T> inline void read(T &a){ T w=1; a=0; char ch=getchar(); for(;ch < '0' || ch > '9';ch=getchar()) if(ch == '-') w=-1; for(;ch>='0'&&ch<='9';ch=getchar()) a=(a<<3)+(a<<1)+(ch^48); a*=w; } template <typename T> inline void ckmax(T &a, T b){a = a > b ? a : b;} template <typename T> inline void ckmin(T &a, T b){a = a < b ? a : b;} #define fi first #define se second #define pb push_back #define mp make_pair #define pii pair<int, int> #define vi vector<int> #define Debug(x) cout << #x << " = " << x << endl #define For(i,l,r) for (int i = l; i <= r; ++i) #define foR(i,l,r) for (int i = l; i >= r; --i) #define mck fflush(stdin) #define gra fflush(stdout) const int N = 5050; int du[N]; int n; int ck () { int res = 0; For (i, 1, n) if (du[i] == 1) res++; if (du[1] != 1) res++; return res; } struct Node { int id, dfn; Node( int Id = 0, int Dfn = 0) { id = Id, dfn = Dfn; } bool operator < (const Node &x) const { return dfn < x.dfn; } } s[N]; int Get (int x) { printf ("dfn %d\n", x); mck, gra; int xx; read(xx); return xx; } int Val (int x, int y) { printf ("dis %d %d\n", x, y); mck, gra; int xx; read(xx); return xx; } int main() { read(n); For (i, 1, n) read(du[i]); int rem = 142; while (ck() > (rem - 1) / 2) { printf ("del\n"); mck, gra; rem--; read(n); For (i, 1, n) read(du[i]); } int cnt = 0; For (i, 1, n) if (du[i] == 1) s[++cnt] = Node(i, Get(i)); if (du[1] != 1) s[++cnt] = Node(1, 1); sort (s + 1, s + cnt + 1); int Ans = 0; For (i, 1, cnt - 1) { Ans += Val(s[i].id, s[i + 1].id); } Ans += Val(s[cnt].id, s[1].id); printf ("! %d\n", Ans / 2); mck, gra; return 0; }
|