This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "network.h"
#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
#define OVL(x,s) for(auto y:x) cout<<y<<s; cout<<"\n";
#ifdef IOI
void dbg_out() { cout << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); }
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__);
#else
#define dbg(...) 1337;
#endif
#define endl "\n"
#define pb push_back
#define F first
#define S second
#define ll long long
#define mod 1000000007
#define all(v) v.begin(),v.end()
void findRoute (int N, int a, int b)
{
    /*
     *  Obviously, this is not a good solution.
     *  Replace it with your own code.
     */
    int n=N;
    vector<int> d[N+1],d2[n+1];
    int f=ping(a,b);
    for(int i=1;i<=n;i++){
        if(i==a||i==b) continue;
        int x=ping(a,i),y=ping(i,b);
        if(x+y+1==f){
            d[x].pb(i);
            d2[y].pb(i);
        }
    }
    for(int i=0;i<=n;i++){
        // dbg(i)
        for(auto x:d[i]){
            // dbg(x)
            travelTo(x);
            break;
            // dbg(x)
        }
    }
    travelTo(b);
}
#ifdef IOI
#include <cstdio>
#include <cstdlib>
#include "network.h"
static const int MAX_N = 1010;
static int N, a, b, M,
           pingCount,
           routeLength, current;
static int di[MAX_N][MAX_N];
static void raiseError (const char* message)
{
    printf ("ERROR\n%s\n", message);
    exit (0);
}
int ping (int i, int j)
{
    if (i < 1 || j < 1 || i > N || j > N || i == j)
        raiseError ("ping called with invalid arguments");
    ++pingCount;
    if (pingCount > M)
        raiseError ("Too many calls to ping");
    return di[i-1][j-1];
}
void travelTo (int k)
{
    if (k < 1 || k > N)
        raiseError ("travelTo called with invalid argument");
    if (k == current || di[current-1][k-1] > 0)
        raiseError ("Travelling to nonadjacent computer");
    ++routeLength;
    if (routeLength > di[a-1][b-1] + 1)
        raiseError ("Route is too long");
    current = k;
}
int main()
{
    scanf ("%d%d%d%d", &N, &a, &b, &M);
    for (int u = 0; u < N; ++u)
        for (int v = 0; v < N; ++v)
            scanf("%d", &di[u][v]);
    pingCount = 0;
    routeLength = 0;
    current = a;
    findRoute (N, a, b);
    if (current != b)
        raiseError ("Message has not reached its target");
    if (routeLength < di[a-1][b-1] + 1)
        raiseError ("Unexpected: route is too short");
    printf ("OK\n");
    return 0;
}
#endif
Compilation message (stderr)
grader.c: In function 'int main()':
grader.c:48:11: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |     scanf ("%d%d%d%d", &N, &a, &b, &M);
      |     ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
grader.c:51:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |             scanf("%d", &distance[u][v]);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |