제출 #532927

#제출 시각아이디문제언어결과실행 시간메모리
532927kebineBosses (BOI16_bosses)C++17
67 / 100
1542 ms964 KiB
#include <bits/stdc++.h>
using namespace std;

int n;
vector<int> vec[5005];
vector<int> temp[5005];
int salary[5005];

long long mon(int x) {
  long long total1 = 1;
  for(auto v: temp[x]) {
    total1 += mon(v);
  }
  return salary[x] = total1;
}

long long bfs(int x) {
  queue<int> q;
  q.push(x);
  bool visited[n+1];
  memset(visited, false, sizeof(visited));
  int fre = 1;
  
  visited[x] = true;

  while(!q.empty()) {
    int a = q.front(); q.pop();

    for(auto v: vec[a]) {
      if(!visited[v]) {
        temp[a].push_back(v);
        fre++;
        visited[v] = true;
        q.push(v);
      }
    }
  }
  if(fre != n) {
    return LLONG_MAX;
  }
  else {
    int c = mon(x);
    long long total1 = 0;
    for(int i= 1; i<=n; i++) {
      total1 += salary[i];
    }
    return total1;
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;

  for(int i = 1; i<=n; i++) {
    int a;
    cin >> a;
    for(int ii = 1; ii<=a; ii++) {
      int b;
      cin >> b;
      vec[b].push_back(i);
    }
  }

  long long min1 = LLONG_MAX;

  for(int i = 1; i<=n; i++) {
    min1 = min(min1, bfs(i));
    for(int ii = 1; ii<=n; ii++) temp[ii].clear();
  }

  cout << min1 << endl;
}

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

bosses.cpp: In function 'long long int bfs(int)':
bosses.cpp:42:9: warning: unused variable 'c' [-Wunused-variable]
   42 |     int c = mon(x);
      |         ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...