제출 #81071

#제출 시각아이디문제언어결과실행 시간메모리
81071xiaowuc1Bosses (BOI16_bosses)C++14
100 / 100
578 ms1444 KiB
#include <bits/stdc++.h>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);

ios_base::sync_with_stdio(false);
cin.tie(NULL);
*/
using namespace std;

const double PI = 2 * acos(0);

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<int, ll> pill;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef vector<vector<ll>> matrix;

int n;
vector<int> edges[5005];

int dist[5005];
int q[5005];
int solve(int curr) {
  for(int i = 1; i <= n; i++) {
    dist[i] = 1 << 25;
  }
  dist[curr] = 0;
  int ql = 0;
  int qr = 0;
  q[qr++] = curr;
  int ret = 0;
  while(ql < qr) {
    curr = q[ql++];
    ret += dist[curr];
    for(int out: edges[curr]) {
      if(dist[out] == 1 << 25) {
        dist[out] = dist[curr] + 1;
        q[qr++] = out;
      }
    }
  }
  if(ql != n) ret = 1 << 30;
  return ret;
}

int main() {
  scanf("%d", &n);
  for(int i = 1; i <= n; i++) {
    int k;
    scanf("%d", &k);
    while(k--) {
      int t;
      scanf("%d", &t);
      edges[t].push_back(i);
    }
  }
  int ret = 1 << 30;
  for(int i = 1; i <= n; i++) {
    ret = min(ret, solve(i));
  }
  printf("%d\n", ret + n);
}

컴파일 시 표준 에러 (stderr) 메시지

bosses.cpp: In function 'int main()':
bosses.cpp:51:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &n);
   ~~~~~^~~~~~~~~~
bosses.cpp:54:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &k);
     ~~~~~^~~~~~~~~~
bosses.cpp:57:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       scanf("%d", &t);
       ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...