# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
289116 | 2020-09-02T11:17:53 Z | TadijaSebez | Friends (BOI17_friends) | C++11 | 420 ms | 11008 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){ if(cmp[A].empty()||cmp[B].empty())return; 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); } if(same.empty())return; 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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Correct | 0 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 |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 5 ms | 1280 KB | Output is correct |
3 | Correct | 3 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 | 2 ms | 896 KB | Output is correct |
8 | Correct | 7 ms | 1536 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 5 ms | 1280 KB | Output is correct |
3 | Correct | 3 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 | 2 ms | 896 KB | Output is correct |
8 | Correct | 7 ms | 1536 KB | Output is correct |
9 | Correct | 1 ms | 512 KB | Output is correct |
10 | Correct | 73 ms | 4732 KB | Output is correct |
11 | Correct | 105 ms | 5752 KB | Output is correct |
12 | Correct | 105 ms | 5496 KB | Output is correct |
13 | Correct | 110 ms | 5632 KB | Output is correct |
14 | Correct | 14 ms | 7808 KB | Output is correct |
15 | Correct | 14 ms | 7808 KB | Output is correct |
16 | Correct | 7 ms | 8576 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Correct | 0 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 | 5 ms | 1280 KB | Output is correct |
11 | Correct | 3 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 | 2 ms | 896 KB | Output is correct |
16 | Correct | 7 ms | 1536 KB | Output is correct |
17 | Correct | 1 ms | 512 KB | Output is correct |
18 | Correct | 73 ms | 4732 KB | Output is correct |
19 | Correct | 105 ms | 5752 KB | Output is correct |
20 | Correct | 105 ms | 5496 KB | Output is correct |
21 | Correct | 110 ms | 5632 KB | Output is correct |
22 | Correct | 14 ms | 7808 KB | Output is correct |
23 | Correct | 14 ms | 7808 KB | Output is correct |
24 | Correct | 7 ms | 8576 KB | Output is correct |
25 | Correct | 1 ms | 384 KB | Output is correct |
26 | Correct | 235 ms | 8440 KB | Output is correct |
27 | Correct | 199 ms | 8056 KB | Output is correct |
28 | Correct | 172 ms | 7296 KB | Output is correct |
29 | Correct | 9 ms | 4864 KB | Output is correct |
30 | Correct | 13 ms | 5888 KB | Output is correct |
31 | Correct | 8 ms | 5888 KB | Output is correct |
32 | Correct | 7 ms | 8576 KB | Output is correct |
33 | Correct | 420 ms | 11008 KB | Output is correct |
34 | Correct | 36 ms | 10872 KB | Output is correct |