제출 #1190104

#제출 시각아이디문제언어결과실행 시간메모리
1190104jioungBitaro’s Party (JOI18_bitaro)C++20
0 / 100
12 ms14920 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define fi first #define se second #define NAME "" #define eb emplace_back #define pii pair<int, int> #define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++) #define REP(i, a, b) for (int i = (a), _b = (b); i >= _b; i--) #define FORD(i, a, b, x) for (int i = (a), _b = (b); i <= _b; i += x) const int MAX = 100005, BLOCK = sqrt(MAX) + 1, LOG = __lg(MAX) + 1, mod = 1e9 + 7; const int INF = 1e18; typedef long long ll; namespace Solution { int n, m, q; vector<int> adj[MAX], radj[MAX]; vector<pii> vi[MAX]; bool vis[MAX]; int dist[MAX]; void solve() { cin >> n >> m >> q; FOR(i, 1, m) { int u, v; cin >> u >> v; adj[u].eb(v); radj[v].eb(u); } FOR(i, 1, n) { vi[i].clear(); vi[i].eb(0, i); } FOR(u, 1, n) { for (auto v : radj[u]) { vector<pii> tmp; vi[v].eb(0, v); int ni = vi[u].size(); int nj = vi[v].size(); int i = 0, j = 0; while (tmp.size() < BLOCK && (i < ni || j < nj)) { if (i == ni || (j < nj && vi[v][j].fi + 1 >= vi[u][i].fi)) { tmp.eb(vi[v][j].fi + 1, vi[v][j].se); vis[vi[v][j].se] = true; j++; } else { tmp.eb(vi[u][i]); vis[vi[u][i].se] = true; i++; } while (i < ni && vis[vi[u][i].se]) i++; while (j < nj && vis[vi[v][j].se]) j++; } vi[v].pop_back(); for (auto &p : tmp) vis[p.se] = false; swap(vi[u], tmp); } } while (q--) { int t, y; cin >> t >> y; vector<int> blocked; blocked.reserve(y); FOR(i, 1, y) { int x; cin >> x; vis[x] = true; blocked.eb(x); } if (y < BLOCK) { int ans = -1; for (auto &p : vi[t]) if (p.fi > ans && !vis[p.se]) ans = p.fi; if(!vis[t]) ans = max(ans, 0LL); cout << ans << '\n'; } else { memset(dist, 0, sizeof(dist)); queue<int> qu; qu.push(t); while (!qu.empty()) { int u = qu.front(); qu.pop(); for (auto v : radj[u]) if (dist[v] < dist[u] + 1) { dist[v] = dist[u] + 1; qu.push(v); } } int ans = -1; FOR(i, 1, t) if (dist[i] > ans && !vis[i]) ans = dist[i]; cout << ans << '\n'; } for (int x : blocked) vis[x] = false; } } } signed main() { if (fopen(NAME ".inp", "r")) { freopen(NAME ".inp", "r", stdin); freopen(NAME ".out", "w", stdout); } ios_base::sync_with_stdio(false); cin.tie(nullptr); Solution::solve(); return 0; }

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

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