제출 #1297493

#제출 시각아이디문제언어결과실행 시간메모리
1297493khoile08Bitaro’s Party (JOI18_bitaro)C++20
100 / 100
1283 ms351948 KiB
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define FOD(i, a, b) for(int i = a; i >= b; i--)
#define fi first
#define se second
#define ll long long
#define db double
#define ii pair<int,int>
#define pb push_back
#define MASK(i) (1LL << i)
#define sq(i) (1LL * (i) * (i))
#define task "task"

const ll INF = 1e18;
const int inf = 1e9;
const int N = 1e5 + 4;
const int M = 2e5 + 4;
const int S = 100;

int n, m, q;
vector<int> g[N], topo;
vector<ii> lp[N], can[N];
int dp[N];
bool in[N];

void lightset(int t, int y, vector<int> &ban) {
    for(int x : ban) in[x] = 1;
    for(ii x : lp[t]) {
        if(!in[x.se]) {
            cout << x.fi << '\n';
            for(int tmp : ban) in[tmp] = 0;
            return;
        }
    }
    for(int x : ban) in[x] = 0;
    cout << -1 << '\n';
}

void heavyset(int t, int y, vector<int> &ban) {
    FOR(i, 1, n) dp[i] = 0;
    for(int x : ban) dp[x] = -1;
    FOR(u, 1, n) {
        if(dp[u] == -1) continue;
        for(int v : g[u]) dp[v] = max(dp[v], dp[u] + 1);
    }
    cout << dp[t] << '\n';
}

signed main() {
    if(fopen(task".inp", "r")) {
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n >> m >> q;
    FOR(i, 1, m) {
        int u, v;
        cin >> u >> v;
        g[u].pb(v);
    }

    FOR(i, 1, n) can[i].pb({0, i});

    FOR(u, 1, n) {
        sort(can[u].begin(), can[u].end(), greater<ii>());
        for(ii x : can[u]) {
            if(!in[x.se]) {
                in[x.se] = 1;
                lp[u].pb(x);
            }
            if(lp[u].size() == S + 1) break;
        }
        assert(lp[u].size() <= S + 1);
        can[u].clear();
        for(ii x : lp[u]) in[x.se] = 0;
        for(int v : g[u]) {
            for(ii x : lp[u]) {
                can[v].pb({x.fi + 1, x.se});
            }
        }
    }

    FOR(i, 1, q) {
        int t, y;
        cin >> t >> y;
        vector<int> ban;
        FOR(j, 1, y) {
            int x;
            cin >> x;
            ban.pb(x);
        }
        if(y <= S) lightset(t, y, ban);
        else heavyset(t, y, ban);
    }
}

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

bitaro.cpp: In function 'int main()':
bitaro.cpp:52:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:53:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...