#pragma GCC optimize "O3,omit-frame-pointer,inline,unroll-loops" #pragma GCC target "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2" #include #include #include #include #include #include #include "bits/stdc++.h" #include #include #include #include #include using namespace std; #ifdef LOCAL inline double GetSeconds() { return static_cast(chrono::duration_cast( chrono::steady_clock::now().time_since_epoch()).count())/1000000000; } #else inline long long GetTSC() { long long lo, hi; asm volatile ("rdtsc": "=a"(lo), "=d"(hi)); return lo + (hi << 32); } inline double GetSeconds() { return GetTSC() / 3.0e9; } #endif struct XorShift { uint64_t x = 88172645463325252ULL; double nl[65536]; XorShift() {} void init(){ double n2 = 1.0 / 65536*2; for(int i=0; i<65536; i++) nl[i] = log(i / 65536.0 + n2); } void setSeed(uint64_t seed) { x = seed; init(); } uint64_t next() { x ^= x << 13; x ^= x >> 7; x ^= x << 17; return x; } int nextInt(int n) { uint64_t upper = 0xFFFFFFFFFFFFFFFFULL / n * n; uint64_t v = next(); while (v >= upper) v = next(); return v % n; } double nextDouble() { uint64_t v = next() >> 11; // 53bit return (double)v / (1ULL << 53); } double nextLog() { return nl[nextInt(65536)]; } }; XorShift xs; #ifdef LOCAL const double TO = 0.9 * 1.2e-0; #else const double TO = 0.9 / 1.2; #endif double starttime, gt; int att,btt,ctt,dtt,ett,ftt,gtt,htt; const int N = 100; const int M = 8; const int NM = 108; const int AL = 5; const int AL2 = 25; int A[NM]; int B[NM]; int D[NM][NM]; int E[NM][NM]; int R[N + 1]; void init(){ int n,m; cin >> n >> m; for(int i=0; i> A[i] >> B[i]; for(int i=0; i D[i][k] + D[k][j]){ D[i][j] = D[i][k] + D[k][j]; } } } } } void newD(int m){ E[m][m] = D[m][m] = 0; int mm = 0, mc = 0, ma = 0, mb = 0; for(int t=0; t<1000; t++){ A[m] = xs.nextInt(1001); B[m] = xs.nextInt(1001); for(int i=0; i D[i][m] + D[m][j]){ tc++; tm += D[i][j] - (D[i][m] + D[m][j]); } } } if(tm > mm || (tm == mm && tc < mc)){ mm = tm; mc = tc; ma = A[m]; mb = B[m]; } } cerr << "mab: " << ma << " " << mb << " mmc: " << mm << " " << mc << endl; A[m] = ma; B[m] = mb; for(int i=0; i D[i][k] + D[k][j]){ D[i][j] = D[i][k] + D[k][j]; } } } } } void solve(){ for(int m=0; m u; for(int i=1; i D[b][j]){ m = D[b][j]; mj = j; } } R[i] = mj; u[mj] = 1; } while(1){ gt = (TO - (GetSeconds() - starttime)) / TO; if(gt <= 0) break; int a = xs.nextInt(N - 1) + 1; int b = xs.nextInt(N - 2) + 1; if(b >= a) b++; else swap(a, b); int cc = D[R[a-1]][R[a]] + D[R[b]][R[b+1]]; int nc = D[R[a-1]][R[b]] + D[R[a]][R[b+1]]; int s = nc - cc; if(s <= 0 || s > xs.nextLog() * gt){ btt++; while(a < b){ swap(R[a++], R[b--]); } } } int ms = 0; for(int i=0; i r; r.emplace_back(0); for(int i=0; i