# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
289112 | 2020-09-02T11:15:13 Z | TadijaSebez | Friends (BOI17_friends) | C++11 | 1000 ms | 11000 KB |
#include <bits/stdc++.h> using namespace std; #define pb push_back const int N=2550; vector<int> E[N],cmp[N]; stack<int> cns; bool in[N],in_stk[N],done[N]; int p,q,a,b; void cl(){for(int i=0;i<N;i++)in[i]=in_stk[i]=done[i]=0;a=b=0;cns=stack<int>();} bool BCK(int idx){ if(a>p||b>q||a+b+cns.size()>p+q)return 0; if(cns.empty())return 1; int u=cns.top();cns.pop(); a++;in[u]=1;in_stk[u]=0;done[u]=1; int cnt=0; for(int v:E[u]){ if(done[v]&&!in[v])b++; if(!done[v]&&!in_stk[v]){ cns.push(v); in_stk[v]=1; cnt++; } } if(BCK(idx)){ cmp[idx].pb(u); return 1; } a--; in[u]=0; for(int v:E[u])if(done[v]&&!in[v])b--; while(cnt--)in_stk[cns.top()]=0,cns.pop(); for(int v:E[u])if(in[v])b++; if(BCK(idx)){ return 1; } for(int v:E[u])if(in[v])b--; done[u]=0; in_stk[u]=1; cns.push(u); return 0; } void Fix(int A,int B){ set<int> F,S,same; for(int i:cmp[A])F.insert(i); for(int i:cmp[B]){ S.insert(i); if(F.count(i))same.insert(i),F.erase(i); } int cnt=0; for(int i:F) for(int j:E[i]) if(!F.count(j)) cnt++; if(cnt>q){ for(int i:same)F.insert(i),S.erase(i); } cmp[A].clear();for(int i:F)cmp[A].pb(i); cmp[B].clear();for(int i:S)cmp[B].pb(i); } int con[N][N]; int main(){ int n; scanf("%i %i %i",&n,&p,&q); for(int i=1;i<=n;i++){ int m;scanf("%i",&m); while(m--){ int j;scanf("%i",&j);j++; con[i][j]=1; E[i].pb(j); } } for(int i=1;i<=n;i++)for(int j=i+1;j<=n;j++)if(con[i][j]+con[j][i]==1)return 0*printf("detention\n"); for(int i=1;i<=n;i++){ cl(); in[i]=done[i]=1;a++; for(int j:E[i]){ cns.push(j); in_stk[j]=1; } if(!BCK(i))return 0*printf("detention\n"); cmp[i].pb(i); sort(cmp[i].begin(),cmp[i].end()); } for(int i=1;i<=n;i++)for(int j=i+1;j<=n;j++)Fix(i,j); int cnt=0; for(int i=1;i<=n;i++)if(cmp[i].size())cnt++; printf("home\n"); printf("%i\n",cnt); for(int i=1;i<=n;i++)if(cmp[i].size()){ printf("%i ",cmp[i].size()); for(int j:cmp[i])printf("%i ",j-1); printf("\n"); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 512 KB | Output is correct |
3 | Correct | 1 ms | 512 KB | Output is correct |
4 | Correct | 1 ms | 512 KB | Output is correct |
5 | Correct | 1 ms | 512 KB | Output is correct |
6 | Correct | 1 ms | 512 KB | Output is correct |
7 | Correct | 1 ms | 512 KB | Output is correct |
8 | Correct | 1 ms | 512 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 14 ms | 1280 KB | Output is correct |
3 | Correct | 7 ms | 1024 KB | Output is correct |
4 | Correct | 2 ms | 1536 KB | Output is correct |
5 | Correct | 2 ms | 1536 KB | Output is correct |
6 | Correct | 1 ms | 1408 KB | Output is correct |
7 | Correct | 3 ms | 896 KB | Output is correct |
8 | Correct | 25 ms | 1536 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 14 ms | 1280 KB | Output is correct |
3 | Correct | 7 ms | 1024 KB | Output is correct |
4 | Correct | 2 ms | 1536 KB | Output is correct |
5 | Correct | 2 ms | 1536 KB | Output is correct |
6 | Correct | 1 ms | 1408 KB | Output is correct |
7 | Correct | 3 ms | 896 KB | Output is correct |
8 | Correct | 25 ms | 1536 KB | Output is correct |
9 | Correct | 1 ms | 384 KB | Output is correct |
10 | Correct | 388 ms | 4736 KB | Output is correct |
11 | Correct | 441 ms | 5632 KB | Output is correct |
12 | Correct | 490 ms | 5624 KB | Output is correct |
13 | Correct | 530 ms | 5888 KB | Output is correct |
14 | Correct | 14 ms | 7808 KB | Output is correct |
15 | Correct | 19 ms | 7808 KB | Output is correct |
16 | Correct | 8 ms | 8576 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 512 KB | Output is correct |
3 | Correct | 1 ms | 512 KB | Output is correct |
4 | Correct | 1 ms | 512 KB | Output is correct |
5 | Correct | 1 ms | 512 KB | Output is correct |
6 | Correct | 1 ms | 512 KB | Output is correct |
7 | Correct | 1 ms | 512 KB | Output is correct |
8 | Correct | 1 ms | 512 KB | Output is correct |
9 | Correct | 1 ms | 384 KB | Output is correct |
10 | Correct | 14 ms | 1280 KB | Output is correct |
11 | Correct | 7 ms | 1024 KB | Output is correct |
12 | Correct | 2 ms | 1536 KB | Output is correct |
13 | Correct | 2 ms | 1536 KB | Output is correct |
14 | Correct | 1 ms | 1408 KB | Output is correct |
15 | Correct | 3 ms | 896 KB | Output is correct |
16 | Correct | 25 ms | 1536 KB | Output is correct |
17 | Correct | 1 ms | 384 KB | Output is correct |
18 | Correct | 388 ms | 4736 KB | Output is correct |
19 | Correct | 441 ms | 5632 KB | Output is correct |
20 | Correct | 490 ms | 5624 KB | Output is correct |
21 | Correct | 530 ms | 5888 KB | Output is correct |
22 | Correct | 14 ms | 7808 KB | Output is correct |
23 | Correct | 19 ms | 7808 KB | Output is correct |
24 | Correct | 8 ms | 8576 KB | Output is correct |
25 | Correct | 1 ms | 384 KB | Output is correct |
26 | Correct | 815 ms | 8444 KB | Output is correct |
27 | Correct | 627 ms | 8056 KB | Output is correct |
28 | Correct | 605 ms | 7404 KB | Output is correct |
29 | Correct | 10 ms | 4864 KB | Output is correct |
30 | Correct | 15 ms | 5888 KB | Output is correct |
31 | Correct | 8 ms | 5888 KB | Output is correct |
32 | Correct | 8 ms | 8808 KB | Output is correct |
33 | Execution timed out | 1088 ms | 11000 KB | Time limit exceeded |
34 | Halted | 0 ms | 0 KB | - |