제출 #1323577

#제출 시각아이디문제언어결과실행 시간메모리
1323577adscodingBitaro’s Party (JOI18_bitaro)C++20
7 / 100
2019 ms589824 KiB
#include <bits/stdc++.h> #define fi first #define se second #define FOR(i, a, b) for (int i = a, _b = b; i <= _b; ++i) #define FORD(i, a, b) for (int i = a, _b = b; i >= _b; --i) #define FORLL(i, a, b) for (ll i = a, _b = b; i <= _b; ++i) #define FORDLL(i, a, b) for (ll i = a, _b = b; i >= _b; --i) #define all(x) x.begin(), x.end() #define uni(x) sort(all(x)), x.erase(unique(all(x)), x.end()) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define dbg(...) debug(#__VA_ARGS__, __VA_ARGS__) template<typename T> void __prine_one(const char *&s, const T &x) { while (*s == ' ') ++s; const char *p = s; int bal = 0; while (*s) { if (*s == '(') ++bal; else if (*s == ')') --bal; else if (*s == ',' && bal == 0) break; ++s; } cerr.write(p, s - p) << " = " << x; if (*s == ',') { cerr << " , "; ++s; } } template<typename... Args> void debug(const char *s, Args... args) { cerr << "[ "; int dummy[] = {0, (__prine_one(s, args), 0)...}; (void)dummy; cerr << " ]\n\n"; } template<class X, class Y> bool maximize(const X &a, const X &b) { if (a < b) { a = b; return true; } return false; } template<class X, class Y> bool minimize(const X &a, const X &b) { if (a > b) { a = b; return true; } return false; } // -------------------------------------------------------------------------------------------- const int maxn = 1e5 + 3, B = 401; int n, m, q; vector<int> g[maxn]; // -------------------------------------------------------------------------------------------- namespace AC { bool vis[maxn]; vector<pii> dp[maxn]; int DP[maxn]; vector<int> topo; void dfs_topo(int u) { vis[u] = 1; for (int v : g[u]) if (!vis[v]) dfs_topo(v); topo.push_back(u); } void solve() { FOR(i, 1, n) { if (vis[i]) continue; dfs_topo(i); } reverse(all(topo)); for (int u : topo) { dp[u].push_back({0, u}); sort(all(dp[u]), greater<pii>()); dp[u].erase(unique(all(dp[u])), dp[u].end()); while (dp[u].size() > B) dp[u].pop_back(); for (int v : g[u]) for (auto &p : dp[u]) dp[v].push_back({p.fi + 1, p.se}); } FOR(i, 1, n) vis[i] = 0; while (q--) { int src, k; cin >> src >> k; vector<int> vec; FOR(i, 1, k) { int x; cin >> x; vec.push_back(x); vis[x] = 1; } if (k < 301) { // cerr << "TYPE1\n"; int res = -1; for (auto &p : dp[src]) { // dbg(p.se); if (!vis[p.se]) { res = max(res, p.fi); } } cout << res << '\n'; } else { // cerr << "TYPE2\n"; FOR(i, 1, n) { DP[i] = vis[i] ? -1 : 0; } for (int u : topo) { if (DP[u] == -1) continue; if (u == src) break; for (int v : g[u]) { DP[v] = max(DP[v], DP[u] + 1); } } cout << DP[src] << '\n'; } for (int x : vec) vis[x] = 0; } } } void solve() { cin >> n >> m >> q; FOR(i, 1, m) { int u, v; cin >> u >> v; g[u].push_back(v); } AC :: solve(); } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define TASK "TEST" if (fopen(TASK".INP", "r")) { freopen(TASK".INP", "r", stdin); freopen(TASK".OUT", "w", stdout); } solve(); return 0; }

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

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