Submission #48365

# Submission time Handle Problem Language Result Execution time Memory
48365 2018-05-12T08:35:03 Z someone_aa Bosses (BOI16_bosses) C++17
0 / 100
2 ms 728 KB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define ull unsigned long long
using namespace std;
const int maxn = 5100;
vector<int>g[maxn], gc[maxn];
bool visited[maxn];
ll result, temp_result;
int n;

ll dfs(int node, int parent) {
    ll tsum = 0LL;
    for(int i:gc[node]) {
        if(i!=parent) {
            tsum += dfs(i, node);
        }
    }
    temp_result += tsum + 1LL;
    return tsum + 1LL;
}

void bfs(int st) {
    for(int i=1;i<=n;i++) gc[i].clear();
    memset(visited, false ,sizeof(visited));
    queue<int>q;
    q.push(st);
    visited[st] = true;

    while(!q.empty()) {
        int curr = q.front();
        q.pop();

        for(int i:g[curr]) {
            if(!visited[i]) {
                visited[i] = true;
                gc[curr].pb(i);
                q.push(i);
            }
        }
    }
    temp_result = 0LL;
    ll temp = dfs(st, -1);
    result = min(result, temp_result);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    int t, u;
    for(int i=1;i<=n;i++) {
        cin>>t;
        for(int j=0;j<t;j++) {
            cin>>u;
            g[u].pb(i);
        }
    }

    result = LLONG_MAX;
    for(int i=1;i<=n;i++) {
        bfs(i);
    }
    cout<<result;
    return 0;
}

Compilation message

bosses.cpp: In function 'void bfs(int)':
bosses.cpp:44:8: warning: unused variable 'temp' [-Wunused-variable]
     ll temp = dfs(st, -1);
        ^~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 616 KB Output is correct
3 Incorrect 2 ms 728 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 616 KB Output is correct
3 Incorrect 2 ms 728 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 616 KB Output is correct
3 Incorrect 2 ms 728 KB Output isn't correct
4 Halted 0 ms 0 KB -