QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#275630 | #6870. Coin | anhduc2701 | WA | 282ms | 6024kb | C++23 | 2.9kb | 2023-12-04 21:49:12 | 2023-12-04 21:49:13 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
int n,m,k;
struct edge{
int u,v,f,c;
edge(){}
edge(int _u,int _v,int _c){
u=_u;
v=_v;
c=_c;
f=0;
}
};
struct Dinic{
vector<edge>ed;
vector<vector<int>>G;
vector<int>level;
vector<int>cd;
int n,source,sink;
void init(int _n,int _source,int _sink){
n=_n;
source=_source;
sink=_sink;
cd.assign(n+2,0);
level.assign(n+2,0);
G.assign(n+2,vector<int>());
}
void addedge(int u,int v,int c){
G[u].pb(ed.size());
ed.pb(edge(u,v,c));
G[v].pb(ed.size());
ed.pb(edge(v,u,0));
}
bool bfs(){
fill(level.begin(),level.end(),-1);
level[source]=0;
queue<int>qu;
qu.push(source);
while(qu.size()){
int u=qu.front();
qu.pop();
for(auto id:G[u]){
if(level[ed[id].v]!=-1 || ed[id].c-ed[id].f<1)continue;
level[ed[id].v]=level[u]+1;
qu.push(ed[id].v);
}
}
if(level[sink]!=-1)return true;
return false;
}
int dfs(int u,int cap){
//cout << u <<' '<<cap<< '\n';
if(u==sink || cap==0)return cap;
for(int&i =cd[u];i<G[u].size();i++){
int id=G[u][i];
if(level[ed[id].v]!=level[u]+1 || ed[id].c-ed[id].f<1)continue;
int c=dfs(ed[id].v,min(cap,ed[id].c-ed[id].f));
if(c==0)continue;
ed[id].f+=c;
ed[id^1].f-=c;
return c;
}
return 0;
}
int Flow(){
int f=0;
while(bfs()){
fill(cd.begin(),cd.end(),0);
while(int pushed=dfs(source,1e9)){
f+=pushed;
}
}
return f;
}
};
int a[3005];
int limit[3005];
int last[3005];
void solve(){
cin >> n >> m >> k;
int source=0;
int sink=n+m*4+1;
Dinic A;
A.init(sink,source,sink);
for(int i=1;i<=n;i++){
cin >> limit[i];
A.addedge(source,i,1);
last[i]=i;
}
int cnt=n;
for(int i=1;i<=m;i++){
int vira=++cnt;
int virb=++cnt;
int a,b;
cin >> a >> b;
A.addedge(a,virb,1);
A.addedge(b,vira,1);
A.addedge(last[a],vira,1e9);
A.addedge(last[b],virb,1e9);
last[a]=++cnt;
last[b]=++cnt;
A.addedge(vira,last[a],limit[a]);
A.addedge(virb,last[b],limit[b]);
}
for(int i=1;i<=k;i++){
int x; cin >> x;
A.addedge(last[x],sink,1e9);
}
cout << A.Flow() << '\n';
}
signed main(){
// freopen("input.inp","r",stdin);
cin.tie(0),cout.tie(0)->sync_with_stdio(0);
int t;
cin >> t;
while(t--){
solve();
}
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 282ms
memory: 6024kb
input:
10 2621 3000 873 542 5 3 3 1 2 8 2 2 4 1 1 2 5 3 1 5 1 2 4 3 1 1 6 3 3 3 1 1 1 1 5 6 2 4 2 2 2 1 5 2 1 3 3 2 2 1 3 1 1 4 3 3 2 4 2 2 1 1 3 1 1 1 2 2 1 2 3 3 2 1 1 5 1 3 3 1 1 3 2 2 2 3 4 4 4 3 1 1 1 1 2 1 1 1 1 1 1 4 2 2 2 2 1 6 2 3 1 3 2 3 1 3 2 1 2 1 3 1 2 1 6 1 3 1 3 2 1 2 2 2 2 4 3 1 3 1 4 1 2 1...
output:
1489 1238 1574 1542 1311 1353 1440 1269 1750 1687
result:
wrong answer 1st lines differ - expected: '1584', found: '1489'