#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; bool printb(bool f) { if (f)printf("Yes\n"); else printf("No\n"); return f; } template void prt(T t = "", string sep = "\n") { cout << t << sep; return; } template void printl(vector a, string sep = " ") { for (int i = 0; i < a.size(); i++) { cout << a[i]; if (i != a.size() - 1)cout << sep; } cout << "\n"; return; } bool prt_isfixed = false; template void prt_fix(T t, string sep = "\n") { if (!prt_isfixed) { cout << fixed << setprecision(15); prt_isfixed = true; } prt(t, sep); } #define all(a) a.begin(),a.end() #define rep(i, n) for (int i = 0; i < (int)(n); i++) /* #pragma GCC target "prefer-vector-width=512" #pragma GCC optimize "Ofast" #pragma GCC optimize("unroll-loops") */ using uint = unsigned int; using llong = long long; using ullong = unsigned long long; using pii = pair; using pll = pair; using pli = pair; using pil = pair; template using vec2 = vector>; template inline bool chmin(T& a, T b) { return (a > b) ? (a = b, true) : false; } template inline bool chmax(T& a, T b) { return (a < b) ? (a = b, true) : false; } bool bitIn(llong a, int b) { return ((a >> b) & 1); } int bitCnt(llong a) { int re = 0; while (a > 0) { if (a & 1)re++; a >>= 1; } return re; } llong powL(llong n, llong i) { llong re = 1; while (i >= 1) { if (i & 1) re *= n; n *= n; i >>= 1; } return re; } llong powL_M(llong n, llong i, llong mod) { llong re = 1; while (i >= 1) { if (i & 1) { re *= n; re %= mod; } n *= n; n %= mod; i >>= 1; } return re; } llong cei(llong a, llong b) { if (a % b == 0)return a / b; else if (a < 0) { return a / b; } else { return a / b + 1; } } llong flo(llong a, llong b) { if (a % b == 0)return a / b; else if (a < 0) { return a / b - 1; } else { return a / b; } } int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 }; int dx2[8] = { -1,-1,1,1,-1,-1,1,1 }, dy2[8] = { 1,-1,-1,1,1,-1,-1,1 }; int dx8[8] = { 0,1,1,1,0,-1,-1,-1 }, dy8[8] = { -1,-1,0,1,1,1,0,-1 }; int rand_range(int min_val, int max_val) { // 乱数生成器 static std::mt19937_64 mt64(123); // [min_val, max_val] の一様分布整数 (int) の分布生成器 std::uniform_int_distribution get_rand_uni_int(min_val, max_val); // 乱数を生成 return get_rand_uni_int(mt64); } void output(vector& a){ prt(a.size()); rep(i,a.size()){ printf("%d %d\n",a[i].first,a[i].second); } } int main() { int n,t; cin>>n>>t; vec2 a(n,vector(n)); rep(i,n)rep(j,n)scanf("%d",&a[i][j]); vector re; {//雑貪欲 bool isFail = false; pii toind; int to=0; rep(i,n){ rep(j,n){ if(chmax(to,a[i][j])){ toind={i,j}; } } } vec2 bo(n,vector(n,false)); int nx,ny; nx=toind.first; ny=toind.second; re.emplace_back(nx,ny); while(re.size()