제출 #1299688

#제출 시각아이디문제언어결과실행 시간메모리
1299688lmaobruhBitaro’s Party (JOI18_bitaro)C++20
7 / 100
2102 ms212408 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ii pair<int, int> #define fi first #define se second #define fo(i,a,b) for (int i = (a); i <= (b); ++i) #define fd(i,a,b) for (int i = (a); i >= (b); --i) #define all(x) x.begin(), x.end() #define pb push_back #define maxi(a,b) a=max(a,b) #define mini(a,b) a=min(a,b) #define er(x) cerr << #x << " = " << (x) << '\n' #define siz(x) ((int)(x).size()) #define ve vector #define _ << ' ' << const int N = 2e5+5, inf = 1e9+10, mod = 1e9+7, sq = 150; int n, m, d[N], deg[N], mxd[N], cnt[N]; ve<int> g[N], rg[N]; ve<ii> res[N]; bool kk[N]; ve<ii> mer(ve<ii> aa, ve<ii> bb) { ve<ii> cc; cc.reserve(siz(aa)+siz(bb)); for (auto &x:aa) maxi(mxd[x.se],x.fi), cc.pb({0,x.se}); for (auto &x:bb) maxi(mxd[x.se],x.fi+1), cc.pb({0,x.se}); sort(all(cc)); cc.resize(unique(all(cc))-cc.begin()); fo(i,0,siz(cc)-1) { cc[i].fi=mxd[cc[i].se]; mxd[cc[i].se]=-1; } sort(all(cc),[&](ii x, ii y)->bool{ if (x.fi!=y.fi) return x.fi>y.fi; return 0; }); if (siz(cc)>sq) cc.resize(sq); return cc; } ve<int> topo; void init() { fo(i,1,n) res[i].pb({0,i}); queue<int> q; fo(i,1,n) if (deg[i]==0) q.push(i); while (q.size()) { int u = q.front(); q.pop(); topo.pb(u); for (int v:g[u]) { deg[v]--; if (deg[v]==0) q.push(v); } } for (int u:topo) { for (int v:g[u]) { res[v]=mer(res[v],res[u]); } } } int brute(int to) { memset(d,-0x3f,sizeof(d)); d[to]=0; fd(i,n-1,0) { int u=topo[i]; for (int v:rg[u]) { maxi(d[v],d[u]+1); } } int mx=-1; fo(i,1,n) if (!kk[i]) maxi(mx,d[i]); return mx; } void solve() { int q; cin >> n >> m >> q; fo(i,1,m) { int u, v; cin >> u >> v; g[u].pb(v); rg[v].pb(u); deg[v]++; } init(); while (q--) { int tt, sz; cin >> tt >> sz; ve<int> busy(sz); fo(i,0,sz-1) cin >> busy[i], kk[busy[i]]=1; if (sz<sq) { int mx=-1; for (auto &p : res[tt]) { if (!kk[p.se]) maxi(mx,p.fi); } cout << mx << '\n'; } else { cout << brute(tt) << '\n'; } fo(i,0,sz-1) kk[busy[i]]=0; } } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen("a.inp","r")) { freopen("a.inp","r",stdin); freopen("a.out","w",stdout); } solve(); }

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

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