# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
39831 |
2018-01-20T12:43:43 Z |
MladenP |
Bosses (BOI16_bosses) |
C++14 |
|
0 ms |
2212 KB |
#include<bits/stdc++.h>
#define STIZE(x) fprintf(stderr, "STIZE%d\n", x);
#define PRINT(x) fprintf(stderr, "%s = %d\n", #x, x);
#define NL(x) printf("%c", " \n"[(x)]);
#define lld long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define endl '\n'
#define mid (l+r)/2
#define all(a) begin(a),end(a)
#define sz(a) int((a).size())
#define LINF 1000000000000000000LL
#define INF 1000000000
#define EPS 1e-9
using namespace std;
#define MAXN 1010
vector<int> adj[MAXN];
lld dist[MAXN], n;
bool pos[MAXN];
queue<pii> q;
lld BFS(int st) {
for(int i = 1; i <= n; i++) pos[i] = 0;
q.push({st, 1});
while(!q.empty()) {
pii v = q.front(); q.pop();
int node = v.fi, weight = v.se;
dist[node] = weight;
pos[node] = 1;
for(auto x : adj[node]) {
if(!pos[x]) {
q.push({x, weight+1});
}
}
}
lld rez = 0;
for(int i = 1; i <= n; i++) {
if(!pos[i]) return LINF;
rez += dist[i];
}
return rez;
}
int main() {
ios::sync_with_stdio(false);cin.tie(0);
cin >> n;
for(int i = 1; i <= n; i++) {
int k; cin >> k;
for(int j = 1; j <= k; j++) {
int x; cin >> x;
adj[x].pb(i);
}
}
lld rez = LINF;
for(int i = 1; i <= n; i++) {
int cur = BFS(i);
if(cur < rez) {
rez = cur;
}
}
cout << rez;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
2212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
2212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
2212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |