# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
46776 |
2018-04-23T07:23:23 Z |
Waschbar |
Bosses (BOI16_bosses) |
C++17 |
|
1319 ms |
1528 KB |
///©Waschbar
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5000;
const int INF = 1e9;
const long long MOD = 1e9+7;
int n, ans;
vector < vector < int > > g(MAXN+1);
int solve(int f) {
vector <int> siz(n+1,0);
vector <bool> used(n+1,0);
queue <int> Q;
stack < pair<int,int> > st;
Q.push(f);
st.push({f,0});
used[f] = 1;
while(!Q.empty()){
f = Q.front();
Q.pop();
for(int i = 0; i < g[f].size(); i++){
int to = g[f][i];
if(used[to]) continue;
Q.push(to);
st.push({to,f});
used[to] = 1;
}
}
if(st.size() != n) return INF;
int cnt = 0;
while(!st.empty()) {
f = st.top().first;
int p = st.top().second;
st.pop();
siz[f]++; cnt += siz[f];
siz[p] += siz[f];
}
return cnt;
}
int main() {
ios_base::sync_with_stdio(false);
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
cin >> n;
for(int f = 1,m; f <= n; f++) {
cin >> m;
for(int i = 1,x; i <= m; i++) {
cin >> x;
g[x].push_back(f);
}
}
ans = INF;
for(int i = 1; i <= n; i++)
ans = min(ans,solve(i));
cout << ans;
return 0;
}
Compilation message
bosses.cpp: In function 'int solve(int)':
bosses.cpp:26:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < g[f].size(); i++){
~~^~~~~~~~~~~~~
bosses.cpp:35:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(st.size() != n) return INF;
~~~~~~~~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
492 KB |
Output is correct |
3 |
Correct |
2 ms |
544 KB |
Output is correct |
4 |
Correct |
2 ms |
656 KB |
Output is correct |
5 |
Correct |
2 ms |
656 KB |
Output is correct |
6 |
Correct |
2 ms |
664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
492 KB |
Output is correct |
3 |
Correct |
2 ms |
544 KB |
Output is correct |
4 |
Correct |
2 ms |
656 KB |
Output is correct |
5 |
Correct |
2 ms |
656 KB |
Output is correct |
6 |
Correct |
2 ms |
664 KB |
Output is correct |
7 |
Correct |
2 ms |
668 KB |
Output is correct |
8 |
Correct |
2 ms |
676 KB |
Output is correct |
9 |
Correct |
2 ms |
768 KB |
Output is correct |
10 |
Correct |
2 ms |
824 KB |
Output is correct |
11 |
Correct |
3 ms |
828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
492 KB |
Output is correct |
3 |
Correct |
2 ms |
544 KB |
Output is correct |
4 |
Correct |
2 ms |
656 KB |
Output is correct |
5 |
Correct |
2 ms |
656 KB |
Output is correct |
6 |
Correct |
2 ms |
664 KB |
Output is correct |
7 |
Correct |
2 ms |
668 KB |
Output is correct |
8 |
Correct |
2 ms |
676 KB |
Output is correct |
9 |
Correct |
2 ms |
768 KB |
Output is correct |
10 |
Correct |
2 ms |
824 KB |
Output is correct |
11 |
Correct |
3 ms |
828 KB |
Output is correct |
12 |
Correct |
10 ms |
1016 KB |
Output is correct |
13 |
Correct |
8 ms |
1176 KB |
Output is correct |
14 |
Correct |
234 ms |
1176 KB |
Output is correct |
15 |
Correct |
19 ms |
1176 KB |
Output is correct |
16 |
Correct |
883 ms |
1276 KB |
Output is correct |
17 |
Correct |
1319 ms |
1396 KB |
Output is correct |
18 |
Correct |
1143 ms |
1528 KB |
Output is correct |