Submission details
Task:Town center
Sender:ind1f
Submission time:2025-10-22 17:10:11 +0300
Language:C++ (C++17)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'long long int f(int)':
input/code.cpp:17:3: error: 'memset' was not declared in this scope
   17 |   memset(d, 0x3f, sizeof(d));
      |   ^~~~~~
input/code.cpp:6:1: note: 'memset' is defined in header '<cstring>'; did you forget to '#include <cstring>'?
    5 | #include <numeric>
  +++ |+#include <cstring>
    6 |

Code

#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <numeric>

using namespace std;

const int N = 1e3 + 5;

int n, m;
vector<int> g[N];
int d[N];

long long f(int u) {
  queue<int> q;
  memset(d, 0x3f, sizeof(d));
  q.push(u);
  d[u] = 0;
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (int x : g[v]) {
      if (d[x] > d[v] + 1) {
        d[x] = d[v] + 1;
        q.push(x);
      }
    }
  }
  return accumulate(d + 1, d + n + 1, 0LL);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    g[a].emplace_back(b);
    g[b].emplace_back(a);
  }
  long long ans = 1e18;
  int res = -1;
  for (int i = 1; i <= n; i++) {
    long long v = f(i);
    if (v < ans) {
      ans = v;
      res = i;
    }
  }
  cout << res << '\n';
  return 0;
}