이 제출은 이전 버전의 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, dp[5069], sm;
vector<long long> adj[5069], adj2[5002];
queue<long long> qu;
void dfs(long long cn) {
dp[cn] = 1;
for (long long i=0; i<adj2[cn].size(); i++) {
long long nn = adj2[cn][i];
dfs(nn);
dp[cn] += dp[nn];
}
sm += dp[cn];
}
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 vd[n+1] = {0};
sm = 0;
qu.push(i);
vd[i] = 1;
while (!qu.empty()) {
u = qu.front();
qu.pop();
for (long long j=0; j<adj[u].size(); j++) {
v = adj[u][j];
if (vd[v] == 0) {
vd[v] = 1;
qu.push(v);
adj2[u].push_back(v);
}
}
}
dfs(i);
for (long long j=1; j<=n; j++) {
adj2[j].clear();
}
if (dp[i]<n) {
continue;
}
ans = min(ans, sm);
}
cout << ans << "\n";
otsumiko
}
컴파일 시 표준 에러 (stderr) 메시지
bosses.cpp: In function 'void dfs(long long int)':
bosses.cpp:15:24: 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]
15 | for (long long i=0; i<adj2[cn].size(); i++) {
| ~^~~~~~~~~~~~~~~~
bosses.cpp: In function 'int main()':
bosses.cpp:41: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]
41 | 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... |