Submission #866725

#TimeUsernameProblemLanguageResultExecution timeMemory
866725YassirSalamaComputer Network (BOI14_network)C++17
25 / 100
68 ms10320 KiB
#include "network.h" #include <iostream> #include <vector> #include <algorithm> #include <unordered_map> #include <set> #include <unordered_set> #include <iomanip> #include <cmath> #include <limits> #include <map> #include <utility> #include <cctype> #include <string> #include <cstring> #include <stack> #include <queue> #include <functional> #include <iterator> using namespace std; #define OVL(x,s) for(auto y:x) cout<<y<<s; cout<<"\n"; 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__); #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() const int MAXN=1500; vector<int> v[MAXN]; bool visited[MAXN][MAXN]; int par[MAXN]; bool vis[MAXN]; void findRoute (int n, int a, int b) { memset(visited,false,sizeof(visited)); for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ if(!(i^j)) continue; if(visited[i][j]) continue; if(ping(i,j)==0){ visited[i][j]=true; visited[j][i]=true; v[i].push_back(j); v[j].push_back(i); } } } memset(par,-1,sizeof(par)); queue<int> q; q.push({a}); bool inqueue[MAXN]; memset(inqueue,false,sizeof(inqueue)); while(!q.empty()){ int node=q.front(); q.pop(); if(vis[node]) continue; vis[node]=true; if(node==b){ vector<int> vv; while(node!=-1){ vv.push_back(node); node=par[node]; } vv.pop_back(); reverse(all(vv)); for(auto x:vv) travelTo(x); return; } for(auto x:v[node]){ if(vis[x]||inqueue[x]) continue; par[x]=node; inqueue[x]=true; q.push(x); } } } #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 dist[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 dist[i-1][j-1]; } void travelTo (int k) { if (k < 1 || k > N) raiseError ("travelTo called with invalid argument"); if (k == current || dist[current-1][k-1] > 0) raiseError ("Travelling to nonadjacent computer"); ++routeLength; if (routeLength > dist[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", &dist[u][v]); pingCount = 0; routeLength = 0; current = a; findRoute (N, a, b); if (current != b) raiseError ("Message has not reached its target"); if (routeLength < dist[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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...