QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#605065#8759. 小班课UESTC_DECAYALIRE 29ms12624kbC++203.3kb2024-10-02 15:20:112024-10-02 15:20:11

Judging History

你现在查看的是最新测评结果

  • [2024-10-02 15:20:11]
  • 评测
  • 测评结果:RE
  • 用时:29ms
  • 内存:12624kb
  • [2024-10-02 15:20:11]
  • 提交

answer

#include<cstdio>
#include<iostream>
#include<vector>
#include<cstring>
#include<queue>
#include<algorithm>
#include<cassert>
#define RI register int
#define CI const int&
using namespace std;
const int N=505,INF=1e9;
int T,n,m,b[N],valid[N],mat[N],rb[N]; vector <int> a[N];
namespace Network_Flow
{
    const int NN=1005,MM=5e6+5;
    struct edge
    {
        int to,nxt,v;
    }e[MM<<1]; int cnt=1,head[NN],cur[NN],dep[NN],s,t;
    inline void addedge(CI x,CI y,CI z)
    {
        e[++cnt]=(edge){y,head[x],z}; head[x]=cnt;
        e[++cnt]=(edge){x,head[y],0}; head[y]=cnt;
    }
    #define to e[i].to
    inline bool BFS(void)
    {
        memset(dep,0,(t+1)*sizeof(int)); dep[s]=1;
        queue <int> q; q.push(s);
        while (!q.empty())
        {
            int now=q.front(); q.pop();
            for (RI i=head[now];i;i=e[i].nxt)
            if (e[i].v&&!dep[to]) dep[to]=dep[now]+1,q.push(to);
        }
        return dep[t];
    }
    inline int DFS(CI now,CI tar,int dis)
    {
        if (now==tar) return dis; int ret=0;
        for (RI& i=cur[now];i&&dis;i=e[i].nxt)
        if (e[i].v&&dep[to]==dep[now]+1)
        {
            int dist=DFS(to,tar,min(dis,e[i].v));
            if (!dist) dep[to]=INF;
            dis-=dist; ret+=dist; e[i].v-=dist; e[i^1].v+=dist;
            if (!dis) return ret;
        }
        if (!ret) dep[now]=INF; return ret;
    }
    #undef to
    inline int Dinic(int ret=0)
    {
        while (BFS()) memcpy(cur,head,(t+1)*sizeof(int)),ret+=DFS(s,t,INF); return ret;
    }
    inline void build(void)
    {
        cnt=1; for (RI i=0;i<=t;++i) head[i]=0;
        for (RI i=1;i<=n;++i) addedge(s,i,1);
        for (RI i=1;i<=m;++i) if (b[i]>0) addedge(n+i,t,b[i]);
        for (RI i=1;i<=n;++i)
        for (RI j=(int)a[i].size()-1;j>=0;--j) addedge(i,n+a[i][j],1);
    }
};
using namespace Network_Flow;
int main()
{
   	//freopen("1.in","r",stdin);
    for (scanf("%d",&T);T;--T)
    {
        scanf("%d%d",&n,&m); s=n+m+1; t=s+1;
        for (RI i=1;i<=n;++i) valid[i]=1;
        for (RI i=1;i<=m;++i) scanf("%d",&b[i]),rb[i]=0;
        for (RI i=1;i<=n;++i)
        {
            int x; scanf("%d",&x); a[i].resize(x);
            for (RI j=0;j<a[i].size();++j) scanf("%d",&a[i][j]);
        }
        build(); int flow=Dinic();
        printf("%d\n",flow);
        for (RI i=1;i<=n;++i)
        {
            mat[i]=0;
            for (RI j=head[i];j;j=e[j].nxt)
            if (1<=e[j].to-n&&e[j].to-n<=m&&e[j].v==0)
            {
                mat[i]=e[j].to-n; ++rb[mat[i]]; break;
            }
        }
        vector <int> ans;
        for (RI k=1;k<=flow;++k)
        {
            bool find=0;
            for (RI i=1;i<=n;++i)
            {
                if (!mat[i]||!valid[i]) continue;
                bool flag=1;
                for (auto x:a[i])
                {
                    if (x==mat[i]) break;
                    if (rb[x]>0) { flag=0; break; }
                }
                if (flag)
                {
                    ans.push_back(i); valid[i]=0;
                    --rb[mat[i]]; find=1; break;
                }
            }
            assert(find==1);
        }
        for (RI i=1;i<=n;++i) if (!mat[i]) ans.push_back(i);
        for (auto x:ans) printf("%d ",x); putchar('\n');
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 4100kb

input:

3
5 5
1 1 1 1 1
4 1 3 2 4
1 5
4 3 4 2 1
2 3 5
1 1
5 3
1 2 2
2 1 2
2 1 2
2 1 3
2 1 3
2 1 3
5 5
1 1 1 1 1
2 1 2
2 5 4
2 3 2
2 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 1
1 1
0
3 3
1 0 2
0
...

output:

1
2 1 3 
0
1 2 3 
1
2 1 3 
1
3 1 2 
2
1 3 2 
3
3 1 2 
0
1 2 3 
2
1 3 2 
2
2 3 1 
2
2 3 1 
2
2 1 3 
1
2 1 3 
2
1 2 3 
1
3 1 2 
1
3 1 2 
2
2 3 1 
2
2 3 1 
0
1 2 3 
2
2 3 1 
0
1 2 3 
1
1 2 3 
2
1 2 3 
1
3 1 2 
3
1 2 3 
3
1 2 3 
0
1 2 3 
1
1 2 3 
2
1 2 3 
2
1 2 3 
2
2 3 1 
2
1 3 2 
1
1 2 3 
2
2 3 1 
1
1...

result:

ok Correct!

Test #4:

score: 0
Accepted
time: 1ms
memory: 4056kb

input:

125
4 4
3 1 0 0
1 2
0
2 1 3
3 2 3 1
4 4
2 0 1 1
2 1 3
2 1 2
2 4 1
0
4 4
2 0 1 1
2 2 3
3 3 2 4
1 2
0
4 4
0 1 1 2
2 3 1
1 4
3 1 2 4
0
4 4
1 1 1 1
2 3 2
2 4 2
0
2 4 2
4 4
2 2 0 0
3 2 1 4
2 3 4
1 2
1 3
4 4
2 0 0 2
1 2
3 3 2 1
2 3 2
2 2 1
4 4
1 2 0 1
1 4
0
0
0
4 4
3 0 0 1
3 2 1 3
0
2 1 4
2 4 3
4 4
1 2 1 ...

output:

3
1 3 4 2 
3
1 2 3 4 
2
1 2 3 4 
3
1 2 3 4 
3
1 4 2 3 
2
1 3 2 4 
2
2 4 1 3 
1
1 2 3 4 
3
1 3 4 2 
3
2 4 1 3 
0
1 2 3 4 
2
1 2 3 4 
2
1 4 2 3 
2
2 3 1 4 
4
2 3 4 1 
2
1 3 2 4 
2
4 3 1 2 
2
3 4 1 2 
3
1 2 3 4 
4
1 2 3 4 
3
1 2 4 3 
1
1 2 3 4 
2
2 3 1 4 
3
1 2 3 4 
2
3 4 1 2 
4
1 2 3 4 
2
1 4 2 3 
3
1...

result:

ok Correct!

Test #5:

score: 0
Accepted
time: 1ms
memory: 3800kb

input:

100
5 5
2 1 2 0 0
0
2 3 2
3 5 4 3
2 1 2
0
5 5
0 2 0 0 3
1 5
0
1 1
0
0
5 5
0 1 3 0 1
2 5 4
2 1 5
0
0
3 3 1 4
5 5
1 1 0 2 1
1 2
0
2 4 5
0
1 4
5 5
0 1 1 2 1
2 4 2
0
2 1 3
0
1 1
5 5
0 0 2 2 1
2 4 3
1 4
0
3 5 4 1
3 5 1 2
5 5
1 2 1 0 1
2 1 2
0
3 3 5 2
2 4 3
0
5 5
1 0 1 1 2
0
1 4
1 3
1 3
0
5 5
1 2 1 1 0
1 ...

output:

3
2 3 4 1 5 
1
1 2 3 4 5 
2
2 5 1 3 4 
3
1 3 5 2 4 
2
1 3 2 4 5 
4
2 5 4 1 3 
3
1 4 3 2 5 
2
2 4 1 3 5 
1
1 2 3 4 5 
4
1 2 3 4 5 
2
2 3 1 4 5 
2
1 4 2 3 5 
3
2 3 5 1 4 
3
3 4 1 2 5 
3
1 2 4 3 5 
3
1 3 2 4 5 
2
1 3 2 4 5 
3
1 4 5 2 3 
1
1 2 3 4 5 
3
2 3 5 1 4 
1
4 1 2 3 5 
2
3 4 1 2 5 
2
1 4 2 3 5 
2...

result:

ok Correct!

Test #6:

score: 0
Accepted
time: 1ms
memory: 3816kb

input:

10
45 47
3 0 2 0 1 1 1 0 2 0 1 0 0 3 0 0 0 4 0 1 0 0 1 2 1 1 1 0 1 1 1 0 0 0 0 1 0 0 0 1 2 4 1 2 1 2 3
7 1 37 21 3 13 43 22
0
10 23 46 22 40 12 19 47 27 16 42
4 29 19 45 35
10 6 26 2 43 41 7 9 16 42 44
5 39 40 34 46 14
3 34 3 38
8 10 5 38 23 19 37 9 34
0
5 31 29 15 13 35
3 40 4 28
1 7
6 29 12 9 35 2...

output:

33
1 7 11 6 12 14 16 17 19 21 25 29 5 30 31 34 3 37 10 4 13 18 24 35 38 39 8 40 15 42 43 36 44 2 9 20 22 23 26 27 28 32 33 41 45 
39
3 10 12 14 16 17 18 19 7 25 24 28 29 30 33 20 35 38 11 34 39 6 23 40 9 21 5 41 1 42 43 36 44 2 15 26 45 31 32 4 8 13 22 27 37 
36
1 3 4 8 10 15 16 17 20 21 18 23 2 25 ...

result:

ok Correct!

Test #7:

score: 0
Accepted
time: 0ms
memory: 4480kb

input:

1
499 497
1 2 0 2 0 1 0 0 0 2 1 2 0 3 1 2 0 0 0 1 0 1 0 2 1 0 1 0 1 1 1 2 0 1 0 1 0 2 2 3 1 1 2 1 0 0 1 0 2 3 0 1 0 0 2 0 1 2 1 0 0 1 2 0 0 2 0 2 0 1 0 1 0 0 1 0 0 1 1 1 1 1 0 0 0 1 2 3 0 0 0 4 2 2 1 2 2 0 1 0 1 0 2 0 1 0 2 0 0 1 1 1 3 2 0 2 2 2 0 1 1 1 1 1 0 1 0 1 1 1 1 1 2 0 0 1 0 2 1 2 1 2 1 0 1 ...

output:

482
2 4 5 9 13 14 30 31 34 41 42 43 48 53 55 58 59 61 63 66 70 74 78 89 91 92 95 104 110 111 112 113 117 120 121 122 124 125 126 135 137 138 139 141 142 143 144 148 153 156 160 164 167 169 171 65 116 172 174 175 176 179 187 188 190 195 197 203 204 205 208 211 214 216 217 223 225 226 228 230 231 232 ...

result:

ok Correct!

Test #8:

score: 0
Accepted
time: 29ms
memory: 12624kb

input:

1
498 499
0 1 1 0 1 0 1 0 0 0 0 2 0 3 1 2 4 0 1 0 1 1 0 0 0 1 1 0 0 2 2 0 1 1 1 0 4 1 1 2 1 0 0 1 2 0 1 2 1 0 1 2 0 2 1 2 2 0 2 2 0 1 0 2 0 0 3 0 1 1 1 1 0 1 0 1 0 0 1 1 0 1 1 0 0 1 0 1 2 1 1 0 1 0 1 0 0 0 1 1 2 0 1 0 2 1 1 2 2 0 0 0 0 2 0 2 1 0 1 0 2 0 1 3 1 1 1 0 1 3 0 1 0 1 0 0 1 3 2 3 2 1 1 0 2 ...

output:

498
35 59 67 74 77 78 79 86 88 90 96 98 108 109 111 113 114 116 117 118 120 129 132 133 143 148 150 157 160 168 170 174 180 181 182 187 193 194 195 196 197 198 199 201 208 209 211 214 216 218 222 226 227 228 172 231 232 233 234 235 239 240 241 245 247 248 250 252 253 256 259 260 263 265 266 268 269 ...

result:

ok Correct!

Test #9:

score: 0
Accepted
time: 0ms
memory: 3812kb

input:

5
99 96
2 0 0 1 1 2 1 0 1 1 1 0 0 0 1 0 1 1 2 1 1 1 1 1 0 1 2 4 0 0 0 2 2 1 1 1 1 1 0 2 0 0 0 1 1 3 0 1 0 0 1 2 1 4 1 2 1 0 1 0 0 2 0 0 0 2 3 2 1 0 1 2 2 0 1 1 0 0 1 0 0 1 2 1 3 1 3 1 3 0 3 0 0 2 2 2
2 14 58
1 55
2 53 69
0
0
1 76
2 23 38
1 41
2 74 54
0
0
2 83 91
0
0
0
1 48
0
0
1 96
2 76 52
1 17
2 51...

output:

48
2 3 6 7 9 12 16 19 20 22 24 26 30 34 23 35 38 39 40 44 45 46 53 57 60 62 65 66 69 71 72 73 74 77 67 78 82 87 88 42 92 93 56 94 95 97 59 99 1 4 5 8 10 11 13 14 15 17 18 21 25 27 28 29 31 32 33 36 37 41 43 47 48 49 50 51 52 54 55 58 61 63 64 68 70 75 76 79 80 81 83 84 85 86 89 90 91 96 98 
44
7 8 1...

result:

ok Correct!

Test #10:

score: 0
Accepted
time: 1ms
memory: 4108kb

input:

5
99 97
0 2 4 0 0 2 0 1 1 1 0 1 0 3 0 1 1 1 1 0 0 1 0 0 1 2 0 0 1 3 1 2 0 2 1 1 1 3 3 1 2 1 0 1 0 1 0 2 0 0 0 0 1 2 3 1 1 1 0 1 0 1 0 0 1 2 1 2 1 1 1 2 2 3 1 1 0 0 1 1 0 0 1 1 2 1 2 2 0 1 1 1 2 0 1 3 1
2 56 63
2 52 45
4 26 56 80 10
2 27 19
1 81
2 38 64
1 83
1 8
3 14 81 60
3 63 28 15
5 59 33 80 88 56...

output:

72
1 3 6 7 8 9 12 13 14 16 20 22 23 24 25 29 30 32 33 35 37 39 40 41 44 34 45 46 47 48 49 53 54 57 58 63 64 65 66 68 70 71 72 11 17 73 55 76 77 78 79 81 18 62 82 83 27 52 85 42 60 87 90 28 91 94 95 96 97 59 98 99 2 4 5 10 15 19 21 26 31 36 38 43 50 51 56 61 67 69 74 75 80 84 86 88 89 92 93 
67
2 7 8...

result:

ok Correct!

Test #11:

score: 0
Accepted
time: 1ms
memory: 3832kb

input:

5
99 98
4 0 1 1 3 2 0 1 4 0 1 1 2 2 1 2 0 0 1 2 1 2 0 1 1 1 2 0 2 0 0 3 0 2 0 0 1 1 1 0 1 1 1 2 0 1 1 0 1 1 1 0 0 1 0 0 2 1 2 3 3 0 0 0 0 0 1 2 1 1 0 3 0 0 0 1 2 0 0 0 0 1 0 2 2 1 2 1 0 1 0 0 1 1 2 3 3 0
5 72 78 90 7 60
6 69 37 10 41 4 59
10 61 85 79 5 7 58 3 55 1 50
6 59 24 30 26 77 21
2 29 21
10 7...

output:

85
3 4 5 8 11 12 15 19 20 21 24 27 29 30 31 35 37 38 40 41 42 47 50 51 53 54 55 46 59 62 63 64 66 67 68 69 70 72 73 74 25 34 76 16 60 14 77 79 33 80 82 83 10 39 84 85 86 87 89 90 49 71 26 44 78 91 58 93 81 94 57 1 32 95 96 97 23 75 2 98 28 43 6 65 99 7 9 13 17 18 22 36 45 48 52 56 61 88 92 
87
2 3 6...

result:

ok Correct!

Test #12:

score: -100
Runtime Error

input:

5
97 100
1 1 1 0 0 1 0 1 1 2 0 1 2 0 1 0 2 3 0 1 0 1 0 1 0 0 1 0 1 2 0 3 2 2 1 0 1 1 2 3 3 1 0 2 1 1 1 2 2 2 0 2 0 3 1 2 2 2 0 1 0 1 1 0 2 0 0 0 0 3 1 0 0 1 0 1 1 0 0 1 1 2 1 2 0 0 1 2 0 1 1 0 2 0 0 1 0 0 2 2
48 80 1 66 89 71 73 40 2 50 99 68 91 31 76 25 67 94 37 6 88 86 28 22 43 62 21 16 17 39 70 1...

output:


result: