제출 #50114

#제출 시각아이디문제언어결과실행 시간메모리
50114MoskriLokoBosses (BOI16_bosses)C++14
100 / 100
1078 ms1148 KiB
#include <bits/stdc++.h>
//#ifdef atom #else #endif
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
#define X first
#define Y second
#define vi vector<int>
#define vvi vector< vi >
#define vii vector< ii >
#define mp make_pair
#define pb push_back
const int maxn = 5005;
vector<int> adj[maxn];
int n;
int vis2[maxn];
int p[maxn];
int inq[maxn];
ll cost[maxn];
ll solve(int x)
{
    memset(vis2, 0, sizeof vis2);
    memset(cost, 0, sizeof cost);
    memset(p, -1, sizeof p);
    vector<int> rev;
    queue<int> Q;
    Q.push(x);
    vis2[x] = 1;
    while(!Q.empty())
    {
        int u = Q.front(); Q.pop();
        rev.pb(u);
        for(int v : adj[u])
        {
            if(!vis2[v])
            {
                vis2[v] = 1;
                p[v] = u;
                Q.push(v);
            }
        }
    }
    if(rev.size() != n) return 1e18;
    reverse(rev.begin(), rev.end());
    ll tot = 0;
    for(int i = 0; i< (int) rev.size(); i++)
    {
        int u = rev[i];
        cost[u]++;
        tot += cost[u];
        if(p[u] != -1) cost[p[u]] += cost[u];
    }
    return tot;
}
int main()
{
    //#ifndef atom
    //freopen(".in", "r", stdin);
    //freopen(".out", "w", stdout);
    //#endif
    scanf("%d", &n);
    for(int i = 1; i<= n; i++)
    {
        int k; scanf("%d", &k);
        for(int j = 1; j<= k; j++)
        {
            int x; scanf("%d", &x);
            adj[x].pb(i);
        }
    }
    ll best = 1e18;
    for(int i = 1; i<= n; i++) best = min(best, solve(i));
    printf("%lld\n", best);
}

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

bosses.cpp: In function 'll solve(int)':
bosses.cpp:43:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(rev.size() != n) return 1e18;
        ~~~~~~~~~~~^~~~
bosses.cpp: In function 'int main()':
bosses.cpp:61:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
bosses.cpp:64:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         int k; scanf("%d", &k);
                ~~~~~^~~~~~~~~~
bosses.cpp:67:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             int x; scanf("%d", &x);
                    ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...