# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
58303 |
2018-07-17T12:42:35 Z |
jovan_b |
Bosses (BOI16_bosses) |
C++17 |
|
2 ms |
676 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
vector <int> drvo[5005];
vector <int> graf[5005];
int cost;
int kost[5005];
bool visited[5005];
void bfs(int v){
visited[v] = true;
queue <int> q;
q.push(v);
while(!q.empty()){
int x = q.front();
q.pop();
for(auto c : graf[x]){
if(!visited[c]){
drvo[x].push_back(c);
visited[c] = 1;
q.push(c);
}
}
}
}
void dfs(int v){
for(auto c : drvo[v]){
dfs(c);
kost[v] += kost[c];
}
cost += kost[v];
}
int main(){
ios_base::sync_with_stdio(false);
cout.precision(10);
cout<<fixed;
int n;
cin >> n;
for(int i=1; i<=n; i++){
int x;
cin >> x;
for(int j=1; j<=x; j++){
int a;
cin >> a;
graf[a].push_back(i);
}
}
int mincost = 1000000000;
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++) visited[j] = 0;
for(int j=1; j<=n; j++) kost[j] = 1;
for(int j=1; j<=n; j++) drvo[j].clear();
cost = 0;
bfs(i);
for(int j=1; j<=n; j++) visited[j] = 0;
dfs(i);
mincost = min(mincost, cost);
}
cout << mincost;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
632 KB |
Output is correct |
2 |
Correct |
2 ms |
632 KB |
Output is correct |
3 |
Incorrect |
2 ms |
676 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
632 KB |
Output is correct |
2 |
Correct |
2 ms |
632 KB |
Output is correct |
3 |
Incorrect |
2 ms |
676 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
632 KB |
Output is correct |
2 |
Correct |
2 ms |
632 KB |
Output is correct |
3 |
Incorrect |
2 ms |
676 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |