QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#428970 | #8759. 小班课 | do_while_true | TL | 93ms | 14128kb | C++20 | 3.4kb | 2024-06-01 23:34:39 | 2024-06-01 23:34:40 |
Judging History
answer
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<assert.h>
#include<ctime>
#define pb emplace_back
#define mp std::make_pair
#define fi first
#define se second
#define dbg(x) cerr<<"In Line "<< __LINE__<<" the "<<#x<<" = "<<x<<'\n';
#define dpi(x,y) cerr<<"In Line "<<__LINE__<<" the "<<#x<<" = "<<x<<" ; "<<"the "<<#y<<" = "<<y<<'\n';
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int>pii;
typedef pair<ll,int>pli;
typedef pair<ll,ll>pll;
typedef vector<int>vi;
typedef vector<ll>vll;
typedef vector<pii>vpii;
template<typename T>T cmax(T &x, T y){return x=x>y?x:y;}
template<typename T>T cmin(T &x, T y){return x=x<y?x:y;}
template<typename T>
T &read(T &r){
r=0;bool w=0;char ch=getchar();
while(ch<'0'||ch>'9')w=ch=='-'?1:0,ch=getchar();
while(ch>='0'&&ch<='9')r=r*10+(ch^48),ch=getchar();
return r=w?-r:r;
}
template<typename T1,typename... T2>
void read(T1 &x, T2& ...y){ read(x); read(y...); }
const int N=2000010;
const int inf=0x7fffffff;
const ll INF=0x7fffffffffffffff;
int S,T,tot;
int head[N],lst[N],pre[N],vis[N],ent=1;
ll flow[N],dis[N];
struct Edge{
int to,nxt;
ll fl,co;
}e[N<<1];
inline void adde(int x,int y,ll w,ll c){
e[++ent]={y,head[x],w,c};head[x]=ent;
e[++ent]={x,head[y],0,-c};head[y]=ent;
}
bool SPFA(){
for(int i=1;i<=tot;i++)lst[i]=pre[i]=0,dis[i]=flow[i]=INF;
queue<int>q;
q.push(S);dis[S]=0;
while(!q.empty()){
int x=q.front();q.pop();
vis[x]=0;
for(int i=head[x];i;i=e[i].nxt){
int v=e[i].to;
if(dis[v]>dis[x]+e[i].co&&e[i].fl){
dis[v]=dis[x]+e[i].co;
pre[v]=x;lst[v]=i;
flow[v]=min(flow[x],e[i].fl);
if(!vis[v]){
q.push(v);
vis[v]=1;
}
}
}
}
return pre[T]>0;
}
void MCMF(){
ll mxfl=0,mnco=0;
while(SPFA()){
mxfl+=flow[T];mnco+=dis[T]*flow[T];
int now=T;
while(now!=S){
e[lst[now]].fl-=flow[T];
e[lst[now]^1].fl+=flow[T];
now=pre[now];
}
}
cout<<mxfl<<'\n';
}
int n,m,p[N],q[N],res[N],bo[N];
vi eg[N];
void solve(){
ent=1;
for(int i=1;i<=tot;i++)head[i]=lst[i]=pre[i]=vis[i]=flow[i]=dis[i]=0;
tot=0;
read(n,m);
for(int i=1;i<=n;i++)p[i]=++tot;
for(int i=1;i<=m;i++)q[i]=++tot;
S=++tot;T=++tot;
for(int i=1;i<=n;i++)adde(S,p[i],1,0);
for(int i=1;i<=m;i++){
int x;read(x);res[i]=x;
adde(q[i],T,x,0);
}
for(int i=1;i<=n;i++){
int k;read(k);
vi().swap(eg[i]);
for(int j=0;j<k;j++){
int y;read(y);
eg[i].pb(y);
adde(p[i],q[y],1,j);
}
}
MCMF();
vpii vec;
for(int x=1;x<=n;x++){
int ok=0;
for(int i=head[x];i;i=e[i].nxt){
int v=e[i].to,fl=e[i].fl,co=e[i].co;
if(!fl && v>=q[1] && v<=q[m]){
ok=1;
bo[x]=co;
}
}
if(ok==0)bo[x]=-1;
}
vi ans;
while(1){
int ok=0;
for(int i=1;i<=n;i++){
int len=eg[i].size();
for(int j=0;j<len;j++){
if(res[eg[i][j]]==0)continue;
else{
if(j==bo[i]){
--res[eg[i][j]];
ans.pb(i);
ok=1;
bo[i]=-2;
}
break;
}
}
}
if(!ok)break;
}
for(int i=1;i<=n;i++)if(bo[i]==-1)ans.pb(i);
for(int i:ans)cout<<i<<' ';
cout<<'\n';
}
signed main(){
// assert(freopen("data.in","r",stdin));
int T;read(T);
while(T--)solve();
#ifdef do_while_true
// cerr<<'\n'<<"Time:"<<clock()<<" ms"<<'\n';
#endif
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 14128kb
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 4 3 2 5 1
output:
5 2 4 5 1 3 5 5 1 2 3 4 5 2 3 4 5 1
result:
ok Correct!
Test #2:
score: 0
Accepted
time: 4ms
memory: 11800kb
input:
250 2 1 2 1 1 1 1 1 1 1 0 2 2 1 1 1 1 2 2 1 2 2 0 2 2 1 2 1 2 1 1 1 1 1 1 2 1 0 0 1 2 1 0 0 2 1 2 1 1 0 1 2 1 0 0 2 1 2 1 1 1 1 1 1 1 1 1 1 2 1 0 1 2 2 2 2 0 1 1 1 2 1 1 1 0 1 1 1 0 1 2 0 1 1 1 2 2 1 1 1 1 2 1 2 2 2 1 1 2 2 1 2 2 1 1 2 0 1 1 2 2 1 2 1 1 0 2 2 2 0 1 1 1 2 1 1 1 1 1 2 1 2 0 1 1 1 1 1 ...
output:
2 1 2 0 1 2 1 2 2 1 2 1 1 0 1 0 1 1 1 2 0 1 2 1 2 1 1 0 1 1 1 2 0 1 0 1 0 1 2 1 2 2 2 1 1 1 1 1 2 1 1 2 1 1 1 2 1 1 1 1 2 1 0 1 2 1 1 1 1 0 1 1 1 2 1 2 0 1 0 1 1 1 2 2 1 2 0 1 0 1 0 1 0 1 2 2 1 2 1 1 1 1 0 1 0 1 0 1 1 1 1 1 0 1 2 1 2 2 1 2 1 2 1 1 1...
result:
ok Correct!
Test #3:
score: 0
Accepted
time: 0ms
memory: 11824kb
input:
166 3 3 1 1 1 0 2 2 3 0 3 3 0 3 0 0 2 1 3 0 3 3 0 0 3 0 2 2 3 0 3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 1 3 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: 0ms
memory: 9780kb
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 1 5 2 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: 6ms
memory: 9816kb
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 12 14 15 16 17 19 21 25 29 30 31 37 38 39 40 42 43 44 5 6 8 10 13 24 35 36 3 4 18 34 2 9 20 22 23 26 27 28 32 33 41 45 39 3 10 12 14 15 16 17 18 19 20 25 28 29 30 31 32 33 35 38 40 42 43 44 45 2 7 9 11 21 24 26 34 36 5 6 23 39 41 1 4 8 13 22 27 37 36 1 3 4 8 10 16 17 20 21 23 25 27 28 29...
result:
ok Correct!
Test #7:
score: 0
Accepted
time: 93ms
memory: 9940kb
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 3 4 5 6 8 10 12 16 17 18 22 27 28 30 31 33 34 35 38 39 40 41 42 43 47 48 49 51 53 56 58 59 60 61 63 64 66 69 70 73 75 76 80 81 82 86 87 88 89 91 92 95 96 101 102 104 106 108 110 111 112 113 117 118 119 120 121 122 123 124 125 126 134 135 136 138 139 141 142 143 144 145 148 149 150 153 155 156 15...
result:
ok Correct!
Test #8:
score: -100
Time Limit Exceeded
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 ...