# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1084905 | 2024-09-07T08:07:17 Z | mrwang | Bitaro’s Party (JOI18_bitaro) | C++14 | 1342 ms | 420812 KB |
#include<bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int,int> #define pll pair<ll,ll> #define fi first #define se second const int maxN=1e5+5; const ll inf=2e18; int n,m,q,dp[maxN+1],block,a[maxN+1],cnt[maxN+1]; vector<int> adj[maxN+1],topo; vector<pii> vec[maxN+1]; bool vis[maxN+1]; void dfs(int u) { vis[u]=true; for(auto v:adj[u]) { if(!vis[v]) { dfs(v); } } topo.push_back(u); } void meg(int u,int v) { vector<pii> vt; int i=0,j=0; for(auto i:vec[u]) { vis[i.fi]=false; } for(auto i:vec[v]) { vis[i.fi]=false; } while(i<vec[u].size()&&j<vec[v].size()&&vt.size()<block) { while(i<vec[u].size()&&vis[vec[u][i].fi]) { i++; } while(j<vec[v].size()&&vis[vec[v][j].fi]) { j++; } if(i>=vec[u].size()||j>=vec[v].size()) { break; } int p1=vec[u][i].se,p2=vec[v][j].se; if(p1+1>p2) { vt.push_back({vec[u][i].fi,p1+1}); vis[vec[u][i].fi]=true; i++; } else { vt.push_back({vec[v][j].fi,p2}); vis[vec[v][j].fi]=true; j++; } } while(i<vec[u].size()&&vt.size()<block) { while(i<vec[u].size()&&vis[vec[u][i].fi]) { i++; } if(i>=vec[u].size()) { break; } vt.push_back({vec[u][i].fi,vec[u][i].se+1}); i++; } while(j<vec[v].size()&&vt.size()<block) { while(j<vec[v].size()&&vis[vec[v][j].fi]) { j++; } if(j>=vec[v].size()) { break; } vt.push_back({vec[v][j].fi,vec[v][j].se}); j++; } swap(vec[v],vt); } void make() { for(auto u:topo) { vec[u].push_back({u,0}); for(auto v:adj[u]) { //cout<<u<<" "<<v<<'\n'; meg(u,v); } } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>m>>q; for(int i=1;i<=m;i++) { int u,v; cin>>u>>v; adj[u].push_back(v); } block=sqrt(n); for(int i=1;i<=n;i++) { if(!vis[i]) { dfs(i); } } memset(dp,0,sizeof(dp)); reverse(topo.begin(),topo.end()); make(); while(q--) { int t,y; cin>>t>>y; if(y>=block) { for(int i=1;i<=n;i++) { dp[i]=0; } } for(int i=1;i<=y;i++) { int u; cin>>u; a[i]=u; dp[u]=INT_MIN; if(y<block) { cnt[u]++; } } if(y>=block) { for(auto u:topo) { for(auto v:adj[u]) { dp[v]=max(dp[v],dp[u]+1); } } if(dp[t]<0) { cout<<-1; } else cout<<dp[t]; } else { int ans=-1; for(auto u:vec[t]) { if(!cnt[u.fi]) { ans=u.se; break; } } cout<<ans; } cout<<'\n'; for(int i=1;i<=y;i++) { cnt[a[i]]=0; } } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 5464 KB | Output is correct |
2 | Correct | 4 ms | 5468 KB | Output is correct |
3 | Correct | 2 ms | 5424 KB | Output is correct |
4 | Correct | 3 ms | 5468 KB | Output is correct |
5 | Correct | 4 ms | 5724 KB | Output is correct |
6 | Correct | 3 ms | 5724 KB | Output is correct |
7 | Correct | 4 ms | 5812 KB | Output is correct |
8 | Correct | 3 ms | 5724 KB | Output is correct |
9 | Correct | 4 ms | 5724 KB | Output is correct |
10 | Correct | 4 ms | 5688 KB | Output is correct |
11 | Correct | 3 ms | 5724 KB | Output is correct |
12 | Correct | 3 ms | 5724 KB | Output is correct |
13 | Correct | 4 ms | 5724 KB | Output is correct |
14 | Correct | 3 ms | 5724 KB | Output is correct |
15 | Correct | 4 ms | 5724 KB | Output is correct |
16 | Correct | 3 ms | 5724 KB | Output is correct |
17 | Correct | 3 ms | 5724 KB | Output is correct |
18 | Correct | 3 ms | 5724 KB | Output is correct |
19 | Correct | 3 ms | 5724 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 5464 KB | Output is correct |
2 | Correct | 4 ms | 5468 KB | Output is correct |
3 | Correct | 2 ms | 5424 KB | Output is correct |
4 | Correct | 3 ms | 5468 KB | Output is correct |
5 | Correct | 4 ms | 5724 KB | Output is correct |
6 | Correct | 3 ms | 5724 KB | Output is correct |
7 | Correct | 4 ms | 5812 KB | Output is correct |
8 | Correct | 3 ms | 5724 KB | Output is correct |
9 | Correct | 4 ms | 5724 KB | Output is correct |
10 | Correct | 4 ms | 5688 KB | Output is correct |
11 | Correct | 3 ms | 5724 KB | Output is correct |
12 | Correct | 3 ms | 5724 KB | Output is correct |
13 | Correct | 4 ms | 5724 KB | Output is correct |
14 | Correct | 3 ms | 5724 KB | Output is correct |
15 | Correct | 4 ms | 5724 KB | Output is correct |
16 | Correct | 3 ms | 5724 KB | Output is correct |
17 | Correct | 3 ms | 5724 KB | Output is correct |
18 | Correct | 3 ms | 5724 KB | Output is correct |
19 | Correct | 3 ms | 5724 KB | Output is correct |
20 | Correct | 92 ms | 8284 KB | Output is correct |
21 | Correct | 94 ms | 8536 KB | Output is correct |
22 | Correct | 106 ms | 8448 KB | Output is correct |
23 | Correct | 95 ms | 8272 KB | Output is correct |
24 | Correct | 574 ms | 268584 KB | Output is correct |
25 | Correct | 621 ms | 279316 KB | Output is correct |
26 | Correct | 616 ms | 278908 KB | Output is correct |
27 | Correct | 886 ms | 419276 KB | Output is correct |
28 | Correct | 889 ms | 419276 KB | Output is correct |
29 | Correct | 896 ms | 419076 KB | Output is correct |
30 | Correct | 953 ms | 413748 KB | Output is correct |
31 | Correct | 873 ms | 402676 KB | Output is correct |
32 | Correct | 883 ms | 413520 KB | Output is correct |
33 | Correct | 600 ms | 260552 KB | Output is correct |
34 | Correct | 522 ms | 217036 KB | Output is correct |
35 | Correct | 610 ms | 258760 KB | Output is correct |
36 | Correct | 776 ms | 338380 KB | Output is correct |
37 | Correct | 727 ms | 310988 KB | Output is correct |
38 | Correct | 762 ms | 339404 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 5464 KB | Output is correct |
2 | Correct | 4 ms | 5468 KB | Output is correct |
3 | Correct | 2 ms | 5424 KB | Output is correct |
4 | Correct | 3 ms | 5468 KB | Output is correct |
5 | Correct | 4 ms | 5724 KB | Output is correct |
6 | Correct | 3 ms | 5724 KB | Output is correct |
7 | Correct | 4 ms | 5812 KB | Output is correct |
8 | Correct | 3 ms | 5724 KB | Output is correct |
9 | Correct | 4 ms | 5724 KB | Output is correct |
10 | Correct | 4 ms | 5688 KB | Output is correct |
11 | Correct | 3 ms | 5724 KB | Output is correct |
12 | Correct | 3 ms | 5724 KB | Output is correct |
13 | Correct | 4 ms | 5724 KB | Output is correct |
14 | Correct | 3 ms | 5724 KB | Output is correct |
15 | Correct | 4 ms | 5724 KB | Output is correct |
16 | Correct | 3 ms | 5724 KB | Output is correct |
17 | Correct | 3 ms | 5724 KB | Output is correct |
18 | Correct | 3 ms | 5724 KB | Output is correct |
19 | Correct | 3 ms | 5724 KB | Output is correct |
20 | Correct | 92 ms | 8284 KB | Output is correct |
21 | Correct | 94 ms | 8536 KB | Output is correct |
22 | Correct | 106 ms | 8448 KB | Output is correct |
23 | Correct | 95 ms | 8272 KB | Output is correct |
24 | Correct | 574 ms | 268584 KB | Output is correct |
25 | Correct | 621 ms | 279316 KB | Output is correct |
26 | Correct | 616 ms | 278908 KB | Output is correct |
27 | Correct | 886 ms | 419276 KB | Output is correct |
28 | Correct | 889 ms | 419276 KB | Output is correct |
29 | Correct | 896 ms | 419076 KB | Output is correct |
30 | Correct | 953 ms | 413748 KB | Output is correct |
31 | Correct | 873 ms | 402676 KB | Output is correct |
32 | Correct | 883 ms | 413520 KB | Output is correct |
33 | Correct | 600 ms | 260552 KB | Output is correct |
34 | Correct | 522 ms | 217036 KB | Output is correct |
35 | Correct | 610 ms | 258760 KB | Output is correct |
36 | Correct | 776 ms | 338380 KB | Output is correct |
37 | Correct | 727 ms | 310988 KB | Output is correct |
38 | Correct | 762 ms | 339404 KB | Output is correct |
39 | Correct | 652 ms | 272356 KB | Output is correct |
40 | Correct | 616 ms | 274720 KB | Output is correct |
41 | Correct | 638 ms | 276132 KB | Output is correct |
42 | Correct | 836 ms | 274380 KB | Output is correct |
43 | Correct | 609 ms | 273864 KB | Output is correct |
44 | Correct | 114 ms | 9808 KB | Output is correct |
45 | Correct | 100 ms | 8788 KB | Output is correct |
46 | Correct | 331 ms | 8876 KB | Output is correct |
47 | Correct | 115 ms | 8612 KB | Output is correct |
48 | Correct | 100 ms | 8276 KB | Output is correct |
49 | Correct | 911 ms | 420016 KB | Output is correct |
50 | Correct | 883 ms | 418648 KB | Output is correct |
51 | Correct | 107 ms | 9444 KB | Output is correct |
52 | Correct | 330 ms | 8636 KB | Output is correct |
53 | Correct | 795 ms | 337856 KB | Output is correct |
54 | Correct | 723 ms | 311756 KB | Output is correct |
55 | Correct | 764 ms | 337056 KB | Output is correct |
56 | Correct | 705 ms | 312032 KB | Output is correct |
57 | Correct | 109 ms | 9552 KB | Output is correct |
58 | Correct | 113 ms | 9808 KB | Output is correct |
59 | Correct | 323 ms | 8788 KB | Output is correct |
60 | Correct | 325 ms | 8880 KB | Output is correct |
61 | Correct | 978 ms | 419020 KB | Output is correct |
62 | Correct | 894 ms | 338524 KB | Output is correct |
63 | Correct | 881 ms | 309996 KB | Output is correct |
64 | Correct | 1342 ms | 418676 KB | Output is correct |
65 | Correct | 1131 ms | 337272 KB | Output is correct |
66 | Correct | 1116 ms | 312128 KB | Output is correct |
67 | Correct | 919 ms | 418680 KB | Output is correct |
68 | Correct | 760 ms | 338520 KB | Output is correct |
69 | Correct | 684 ms | 307928 KB | Output is correct |
70 | Correct | 925 ms | 419024 KB | Output is correct |
71 | Correct | 846 ms | 338368 KB | Output is correct |
72 | Correct | 732 ms | 311248 KB | Output is correct |
73 | Correct | 953 ms | 418980 KB | Output is correct |
74 | Correct | 815 ms | 338608 KB | Output is correct |
75 | Correct | 738 ms | 310992 KB | Output is correct |
76 | Correct | 893 ms | 420812 KB | Output is correct |
77 | Correct | 879 ms | 419340 KB | Output is correct |
78 | Correct | 912 ms | 419536 KB | Output is correct |
79 | Correct | 108 ms | 9668 KB | Output is correct |
80 | Correct | 290 ms | 8700 KB | Output is correct |
81 | Correct | 95 ms | 8528 KB | Output is correct |
82 | Correct | 930 ms | 414916 KB | Output is correct |
83 | Correct | 891 ms | 404168 KB | Output is correct |
84 | Correct | 907 ms | 413640 KB | Output is correct |
85 | Correct | 875 ms | 402640 KB | Output is correct |
86 | Correct | 914 ms | 413896 KB | Output is correct |
87 | Correct | 892 ms | 403396 KB | Output is correct |
88 | Correct | 108 ms | 9632 KB | Output is correct |
89 | Correct | 107 ms | 9652 KB | Output is correct |
90 | Correct | 297 ms | 8784 KB | Output is correct |
91 | Correct | 291 ms | 8784 KB | Output is correct |
92 | Correct | 93 ms | 8284 KB | Output is correct |
93 | Correct | 95 ms | 8528 KB | Output is correct |
94 | Correct | 640 ms | 262092 KB | Output is correct |
95 | Correct | 539 ms | 217284 KB | Output is correct |
96 | Correct | 630 ms | 259464 KB | Output is correct |
97 | Correct | 529 ms | 220364 KB | Output is correct |
98 | Correct | 608 ms | 260552 KB | Output is correct |
99 | Correct | 546 ms | 219336 KB | Output is correct |
100 | Correct | 134 ms | 9804 KB | Output is correct |
101 | Correct | 112 ms | 9808 KB | Output is correct |
102 | Correct | 295 ms | 8788 KB | Output is correct |
103 | Correct | 303 ms | 8748 KB | Output is correct |
104 | Correct | 99 ms | 8284 KB | Output is correct |
105 | Correct | 98 ms | 8276 KB | Output is correct |
106 | Correct | 790 ms | 338760 KB | Output is correct |
107 | Correct | 816 ms | 312784 KB | Output is correct |
108 | Correct | 772 ms | 339668 KB | Output is correct |
109 | Correct | 701 ms | 310948 KB | Output is correct |
110 | Correct | 785 ms | 340044 KB | Output is correct |
111 | Correct | 718 ms | 312160 KB | Output is correct |
112 | Correct | 114 ms | 9812 KB | Output is correct |
113 | Correct | 115 ms | 9808 KB | Output is correct |
114 | Correct | 291 ms | 8636 KB | Output is correct |
115 | Correct | 290 ms | 8860 KB | Output is correct |
116 | Correct | 95 ms | 8512 KB | Output is correct |
117 | Correct | 96 ms | 8284 KB | Output is correct |
118 | Correct | 935 ms | 418832 KB | Output is correct |
119 | Correct | 823 ms | 338924 KB | Output is correct |
120 | Correct | 715 ms | 310476 KB | Output is correct |
121 | Correct | 911 ms | 418836 KB | Output is correct |
122 | Correct | 760 ms | 337488 KB | Output is correct |
123 | Correct | 684 ms | 310260 KB | Output is correct |
124 | Correct | 894 ms | 418636 KB | Output is correct |
125 | Correct | 755 ms | 339408 KB | Output is correct |
126 | Correct | 687 ms | 309768 KB | Output is correct |