이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
using namespace std;
const int INF=1e9;
vector < vector < int > > g;
int main() {
ios_base::sync_with_stdio(false);
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int n;
cin >> n;
g.resize(n+1);
for (int i=1; i<=n; i++) {
int k;
cin >> k;
while (k--) {
int a;
cin >> a;
g[a].push_back(i);
}
}
/*for (int i=1; i<=n; i++) {
for (int j=0; j<g[i].size(); j++)
cout << g[i][j] << " ";
cout << "\n";
}*/
int ans=INF;
for (int i=1; i<=n; i++) {
stack < pair < int,int > > st;
queue < pair < int,int > > q;
vector < bool > used(n+1,0);
vector < int > vc(n+1,0);
q.push({i,-1});
used[i]=1;
while (!q.empty()) {
pair < int,int > v=q.front();
//cout << i << "->" << v.fi << " " << v.se << "\n";
st.push(v);
q.pop();
for (int i=0; i<g[v.fi].size(); i++) {
int to=g[v.fi][i];
if (!used[to]) {
used[to]=1;
q.push({to,v.fi});
}
}
}
while (!st.empty()) {
pair < int,int > v=st.top();
st.pop();
if (!st.empty()) {
vc[v.fi]++;
vc[v.se]+=vc[v.fi];
}
else
vc[v.fi]++;
}
int cnt=0;
bool ind=0;
for (int i=1; i<=n; i++) {
if (!vc[i]) {
ind=1;
break;
}
cnt+=vc[i];
}
if (!ind)
ans=min(ans,cnt);
}
cout << ans;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
bosses.cpp: In function 'int main()':
bosses.cpp:55:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0; i<g[v.fi].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... |