#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()
vector<int> path;
int n;
int c;
set<int> lst;
map<pair<int,int>,int> mp;
int pp(int l,int r){
if(mp.count({l,r})||mp.count({r,l})) return mp[{l,r}];
else return mp[{l,r}]=ping(l,r);
}
void solve(int l,int r){
int k=ping(l,r);
for(auto x:lst){
if(l==x||r==x) continue;
int a=ping(l,x);
int b=ping(x,r);
if(a+b+1==k) {
path.pb(x);
lst.erase(x);
solve(x,r);
return;
}
}
}
void findRoute (int N, int a, int b)
{
/*
* Obviously, this is not a good solution.
* Replace it with your own code.
*/
n=N;
c=ping(a,b);
// path.resize(c+1,0);
lst.erase(a);
lst.erase(b);
for(int i=1;i<=n;i++) lst.insert(i);
solve(a,b);
for(auto x:path){
// dbg(x)
travelTo(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
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 |
1 |
Incorrect |
60 ms |
4192 KB |
Too many calls to ping |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
61 ms |
4240 KB |
Travelling to nonadjacent computer |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
62 ms |
4192 KB |
Travelling to nonadjacent computer |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
60 ms |
4176 KB |
Too many calls to ping |
2 |
Halted |
0 ms |
0 KB |
- |