제출 #530606

#제출 시각아이디문제언어결과실행 시간메모리
530606Killer2501Bitaro’s Party (JOI18_bitaro)C++14
7 / 100
2090 ms249320 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define ull unsigned long long #define pb push_back #define pll pair<ll, ll> #define pii pair<int, int> #define fi first #define se second using namespace std; const int N = 2e5+5; const int M = 300; const int mod = 1e9+7; const ll base = 75; const int inf = 1e9; int m, n, t, b[N], d[N], lab[N], q; int k, a[N]; pii dp[N][M]; int ans, tong; vector<int> adj[N]; vector<int> vi; string s[N]; bool vis[N]; ll pw(ll k, ll n) { ll total = 1; for(; n; n >>= 1) { if(n&1)total = total * k % mod; k = k * k % mod; } return total; } void add(int &x, int y) { x += y; if(x >= mod)x -= mod; } int findp(int u) { return lab[u] < 0 ? u : lab[u] = findp(lab[u]); } void hop(int u, int v) { u = findp(u); v = findp(v); if(u == v)return; if(lab[u] > lab[v])swap(u, v); lab[u] += lab[v]; lab[v] = u; } bool cmp(const int& x, const int& y) { return d[x] > d[y]; } void sol() { cin >> n >> m >> q; for(int i = 1; i <= m; i ++) { int x, y; cin >> x >> y; adj[y].pb(x); } for(int i = 1; i <= n; i ++)for(int j = 0; j < M; j ++)dp[i][j].fi = -1; for(int u = 1; u <= n; u ++) { vis[u] = true; vi.pb(u); for(int v: adj[u]) { for(int j = 0; j < M; j ++) { if(dp[v][j].fi == -1)break; d[dp[v][j].se] = max(d[dp[v][j].se], dp[v][j].fi+1); if(!vis[dp[v][j].se]) { vis[dp[v][j].se] = true; vi.pb(dp[v][j].se); } } } sort(vi.begin(), vi.end(), cmp); for(int j = 0; j < min((int)vi.size(), M); j ++) { dp[u][j].fi = d[vi[j]]; dp[u][j].se = vi[j]; } for(int j = 0; j < (int)vi.size(); j ++) { vis[vi[j]] = false; d[vi[j]] = 0; } } fill_n(d, n+1, -1); while(q -- > 0) { cin >> k >> n; for(int i = 1; i <= n; i ++) { cin >> a[i]; vis[a[i]] = true; } if(dp[k][0].fi == -1)cout << -1 << '\n'; else { ans = -1; if(n >= M) { d[k] = 0; for(int u = k; u > 0; u --) { if(d[u] == -1)continue; if(!vis[u])ans = max(ans, d[u]); for(int v: adj[u])d[v] = max(d[u]+1, d[v]); } for(int u = 1; u <= k; u ++)d[u] = -1; } else { for(int i = 0; i < M; i ++) { if(!vis[dp[k][i].se]) { ans = dp[k][i].fi; break; } } } cout << ans << '\n'; } for(int i = 1; i <= n; i ++)vis[a[i]] = false; } } int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); #define task "test" if(fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } int test = 1; //cin >> test; while(test -- > 0)sol(); return 0; }

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

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