Submission #851130

# Submission time Handle Problem Language Result Execution time Memory
851130 2023-09-18T14:57:22 Z Benmath Bosses (BOI16_bosses) C++14
67 / 100
1500 ms 936 KB
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>

using namespace std;
int n;
vector<int> v[5010];
int vis[5010];
int vis_dfs[5010];
int subtree[5010];
vector<int> adjl[5010];

int brojac = 0;
int brojac_posj = 0;
void dfs (int s){
    vis_dfs[s]++;
    subtree[s]++;
    for(int i = 0; i < adjl[s].size(); i++){
        if(vis_dfs[adjl[s][i]] == 0){
            dfs(adjl[s][i]);
            subtree[s] += subtree[adjl[s][i]];
            
        }
    }
    brojac = brojac + subtree[s];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for (int i = 1; i <= n; i++){
        int x;
        cin >> x;
        for(int j = 0;j < x;j++){
            int y;
            cin >> y;
            v[i].push_back(y);
        }
    }
    int ans = 1e9;
    
    for(int i = 1; i <= n; i++){
        brojac_posj = 0;
        for(int j = 1; j <= n; j++){
            vis[j] = 0;
            vis_dfs[j] = 0;
            subtree[j] = 0;
            adjl[j].clear();
        }
        vis[i]++;
        brojac_posj++;
        brojac = 0;
        queue<int>q;
        q.push(i);
        while (!q.empty()){
            int a = q.front();
            q.pop();
            vector<int>pronadeni;
            for (int j = 1; j <= n; j++){
                if (vis[j] == 0){
                    for (int k = 0; k < v[j].size(); k++){
                        if(v[j][k] == a){
                            pronadeni.push_back(j);
                            break;
                        }
                    }
                }
            }
            for (int j = 0; j < pronadeni.size(); j++){
                adjl[a].push_back(pronadeni[j]);
                vis[pronadeni[j]]++;
                brojac_posj++;
                q.push(pronadeni[j]);
            }
             
            
        }
        
        if(brojac_posj == n){
        dfs (i);
        ans = min(ans, brojac);
        }
       
        
    }
    cout << ans;
}

Compilation message

bosses.cpp: In function 'void dfs(int)':
bosses.cpp:24:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     for(int i = 0; i < adjl[s].size(); i++){
      |                    ~~^~~~~~~~~~~~~~~~
bosses.cpp: In function 'int main()':
bosses.cpp:68:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |                     for (int k = 0; k < v[j].size(); k++){
      |                                     ~~^~~~~~~~~~~~~
bosses.cpp:76:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |             for (int j = 0; j < pronadeni.size(); j++){
      |                             ~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 4 ms 604 KB Output is correct
11 Correct 5 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 4 ms 604 KB Output is correct
11 Correct 5 ms 604 KB Output is correct
12 Correct 27 ms 812 KB Output is correct
13 Correct 12 ms 796 KB Output is correct
14 Execution timed out 1590 ms 936 KB Time limit exceeded
15 Halted 0 ms 0 KB -