제출 #218627

#제출 시각아이디문제언어결과실행 시간메모리
218627Ruxandra985Bosses (BOI16_bosses)C++14
0 / 100
5 ms512 KiB
#include <bits/stdc++.h>
#define DIMN 5010
using namespace std;
priority_queue <pair <int,int> > h;
vector <int> v[DIMN];
int d[DIMN] , tt[DIMN] , lvl[DIMN];
int main()
{
    FILE *fin = stdin;
    FILE *fout = stdout;
    int n , i , k , x , sol , root , nod , vecin ,  niv , j , sum , stabilit = 0;
    fscanf (fin,"%d",&n);
    for (i = 1 ; i <= n ; i++){
        fscanf (fin,"%d",&k);
        if (!k)
            stabilit = i;
        for (j = 1 ; j <= k ; j++){
            fscanf (fin,"%d",&x);
            v[x].push_back(i); /// x poate fi seful lui i
        }
    }
    sol = 2000000000;
    for (root = 1 ; root <= n ; root++){
        if (stabilit)
            root = stabilit;
        h.push(make_pair(-1 , root));
        memset (lvl , 0 , sizeof(lvl));
        lvl[root] = 1;
        tt[root] = 0;
        sum = 1;
        while (!h.empty()){
            nod = h.top().second;
            niv = -h.top().first;
            h.pop();
            if (lvl[nod] != niv){
                continue;
            }

            for (i = 0 ; i < v[nod].size() ; i++){
                vecin = v[nod][i];
                if (lvl[vecin] == 0 || lvl[vecin] > lvl[nod] + 1){
                    sum = sum - lvl[vecin] + lvl[nod] + 1;
                    lvl[vecin] = lvl[nod] + 1;
                    tt[vecin] = nod;
                    h.push(make_pair(-lvl[vecin] , vecin));
                }
            }

        }

        sol = min(sol , sum);
        if (stabilit)
            break;

    }
    fprintf (fout,"%d",sol);
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

bosses.cpp: In function 'int main()':
bosses.cpp:39:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (i = 0 ; i < v[nod].size() ; i++){
                          ~~^~~~~~~~~~~~~~~
bosses.cpp:12:12: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     fscanf (fin,"%d",&n);
     ~~~~~~~^~~~~~~~~~~~~
bosses.cpp:14:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         fscanf (fin,"%d",&k);
         ~~~~~~~^~~~~~~~~~~~~
bosses.cpp:18:20: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             fscanf (fin,"%d",&x);
             ~~~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...