이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
#include <iostream>
#include<vector>
#include <queue>
using namespace std;
long long bfs(int v, vector<vector<int>> &g) {
queue<int> q;
q.push(v);
int n = g.size();
vector<long long> deep(n, 1e10);
deep[v] = 1;
while (q.size() > 0) {
int u = q.front();
q.pop();
for (int i = 0; i < g[u].size(); ++i) {
if (deep[g[u][i]] > 1000000) {
deep[g[u][i]] = deep[u] + 1;
q.push(g[u][i]);
}
}
}
long long summ = 0;
for(int i = 0; i < n; ++i) {
summ += deep[i];
}
return summ;
}
int main()
{
int n;
cin >> n;
vector<vector<int>> g(n);
for (int i = 0; i < n; ++i) {
int k;
cin >> k;
for (int j = 0; j < k; ++j) {
int v;
cin >> v;
--v;
g[v].push_back(i);
}
}
long long total_cost = 1000000000000;
for (int i = 0; i < n; ++i) {
long long ans = bfs(i, g);
if(ans < total_cost) {
total_cost = ans;
}
}
cout << total_cost;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
bosses.cpp: In function 'long long int bfs(int, std::vector<std::vector<int> >&)':
bosses.cpp:24:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | for (int i = 0; i < g[u].size(); ++i) {
| ~~^~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |