이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define nyahalo ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define otsumiko exit(0);
#define mikodanye priority_queue<pair<long long, long long>, vector<pair<long long, long long> >, greater<pair<long long, long long> > >
#define mikochi priority_queue<long long, vector<long long>, greater<long long> >
long long n, k, x, u, v, ans = 1e10, sm;
vector<long long> adj[5069];
queue<long long> qu;
int main() {
nyahalo
cin >> n;
for (long long i=1; i<=n; i++) {
cin >> k;
for (long long j=1; j<=k; j++) {
cin >> x;
adj[x].push_back(i);
}
}
for (long long i=1; i<=n; i++) {
long long dp[n+1], ps[n+1] = {0};
memset(dp, -1, sizeof(dp));
sm = 0;
qu.push(i);
dp[i] = 0;
ps[0]++;
while (!qu.empty()) {
u = qu.front();
qu.pop();
for (long long j=0; j<adj[u].size(); j++) {
v = adj[u][j];
if (dp[v] == -1) {
dp[v] = dp[u]+1;
ps[dp[v]]++;
qu.push(v);
}
}
}
for (long long i=0; i<n; i++) {
if (i>0) {
ps[i] += ps[i-1];
}
sm += n-ps[i];
}
sm += n;
if (ps[n-1]<n) {
continue;
}
ans = min(ans, sm);
}
cout << ans << "\n";
otsumiko
}
컴파일 시 표준 에러 (stderr) 메시지
bosses.cpp: In function 'int main()':
bosses.cpp:33:28: 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]
33 | for (long long j=0; j<adj[u].size(); j++) {
| ~^~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |