QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#275635#6870. Coinanhduc2701WA 375ms7916kbC++232.9kb2023-12-04 21:54:452023-12-04 21:54:46

Judging History

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

  • [2023-12-04 21:54:46]
  • 评测
  • 测评结果:WA
  • 用时:375ms
  • 内存:7916kb
  • [2023-12-04 21:54:45]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#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();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 375ms
memory: 7916kb

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'