제출 #992303

#제출 시각아이디문제언어결과실행 시간메모리
992303Neco_arcBitaro’s Party (JOI18_bitaro)C++17
100 / 100
1394 ms419920 KiB
#include <bits/stdc++.h>
//#include <bits/debug.hpp>

#define ll long long
#define all(x) x.begin(), x.end()
#define Neco "Bitaro Party"
#define resp(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())
#define getbit(x,i) ((x >> i)&1)
#define _left id * 2, l, mid
#define _right id * 2 + 1, mid + 1, r
#define cntbit(x) __builtin_popcountll(x)
#define fi(i, a, b) for(int i = a; i <= b; i++)
#define fid(i, a, b) for(int i = a; i >= b; i--)
#define maxn (int) 2e5 + 7

using namespace std;

const ll mod = 1e9 + 7; //972663749
const ll base = 911382323;
const int Sqrt = 371;

int n, m, q;
int vis[maxn], spe[maxn], dist[maxn];
vector<int> edges[maxn];
vector<pair<int, int>> dp[maxn];

void CASE1(int u, int del) {
    for(auto [w, x] : dp[u]) if(spe[x] != del) {
        return cout << w << '\n', void();
    }
    cout << -1 << '\n';
}

void CASE2(int u, int del) {
    fi(i, 1, n) dist[i] = -1;
    fi(x, 1, n) {
        if(spe[x] != del) dist[x] = 0;
        for(int y : edges[x]) if(dist[y] != -1) {
            dist[x] = max(dist[x], dist[y] + 1);
        }
    }

    cout << dist[u] << '\n';
}

void solve()
{
    cin >> n >> m >> q;
    fi(i, 1, m) {
        int x, y; cin >> x >> y;
        edges[y].push_back(x);
    }

    vector<int> P;

    fi(i, 1, n) {
        P = {i}, dist[i] = 0;
        for(int u : edges[i]) for(auto [w, x] : dp[u]) {

            if(vis[x] == i) dist[x] = max(dist[x], w + 1);
            else dist[x] = w + 1, vis[x] = i, P.push_back(x);
        }

        sort(all(P), [](const int x, const int y) { return dist[x] < dist[y]; } );
        while(dp[i].size() <= Sqrt && !P.empty()) {
            dp[i].push_back({dist[P.back()], P.back()});
            P.pop_back();
        }
    }

    fi(i, 1, q) {
        int x, u, T; cin >> x >> T;
        fi(_, 1, T) cin >> u, spe[u] = i;

        if(T < Sqrt) CASE1(x, i);
        else CASE2(x, i);

    }

}


int main()
{

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    if(fopen(Neco".inp", "r")) {
        freopen(Neco".inp", "r", stdin);
        freopen(Neco".out", "w", stdout);
    }


    int nTest = 1;
//    cin >> nTest;


    while(nTest--)
    {
        solve();
    }


    return 0;
}

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

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