답안 #533215

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
533215 2022-03-05T06:45:04 Z kebine Bosses (BOI16_bosses) C++17
0 / 100
1 ms 332 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll n;
vector<ll> adj[5005];
ll dist[5005];
bool vis[5005];

ll bfs(ll x, ll sum) {
  queue <ll> q;
  q.push(x);
  dist[x] = 1;
  vis[x] = true;
  int cnt = 0;
  while(!q.empty()) {
    ll cur = q.front();
    cnt++;
    q.pop();
    for(ll i = 0; i < adj[cur].size(); i++) {
      ll next = adj[cur][i];
      if (!vis[next]) {
        vis[next] = true;
        dist[next] = dist[cur] + 1;
        sum += dist[next];
        q.push(next);
      }
    }
  }
  if (cnt >= n) {
    return sum;
  }
  return 1e16;
  
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for(ll i = 1; i <= n; i++) {
    ll k;
    cin >> k;
    for(ll j = 0; j < k; j++) {
      ll next;
      cin >> next;
      adj[next].push_back(i);
      //cout << next << " " << i << endl;
    }
  }
  
  ll mn = 1e16;
  for(ll i = 1; i <= n; i++) {
    int ans = bfs(i, 1);
    if (ans < mn) {
      mn = ans;
    }
  }
  cout << mn << "\n";
  
}

Compilation message

bosses.cpp: In function 'long long int bfs(long long int, long long int)':
bosses.cpp:19:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     for(ll i = 0; i < adj[cur].size(); i++) {
      |                   ~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -