QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#287733 | #3855. Regional development | LaStataleBlue# | WA | 1ms | 3684kb | C++23 | 2.2kb | 2023-12-20 22:18:56 | 2023-12-20 22:18:57 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using pi = pair<int,int>;
#define sz(x) int((x).size())
template<class F> struct Dinic{
struct Edge{int to,rev; F cap;};
int N; vector<vector<Edge>> adj;
void init(int _N){ N = _N; adj.resize(N); }
pi ae(int a,int b,F cap,F rcap = 0) {
assert(min(cap,rcap)>=0);
adj[a].push_back({b,sz(adj[b]),cap});
adj[b].push_back({a,sz(adj[a])-1,rcap});
return {a,sz(adj[a])-1};
}
F edgeFlow(pi loc){
const Edge& e = adj.at(loc.first).at(loc.second);
return adj.at(e.to).at(e.rev).cap;
}
vector<int> lev,ptr;
bool bfs(int s,int t){
lev = ptr = vector<int>(N);
lev[s]=1; queue<int> q({s});
while(sz(q)){
int u = q.front(); q.pop();
for(auto &e : adj[u]) if(e.cap && !lev[e.to]){
q.push(e.to), lev[e.to] = lev[u]+1;
if(e.to == t)return 1;
}
}
return 0;
}
F dfs(int v,int t,F flo){
if(v==t)return flo;
for(int &i = ptr[v]; i<sz(adj[v]);i++){
Edge &e = adj[v][i];
if(lev[e.to]!=lev[v]+1 || !e.cap) continue;
if(F df = dfs(e.to,t,min(flo,e.cap))){
e.cap-=df; adj[e.to][e.rev].cap+=df;
return df;
}
}
return 0;
}
F maxFlow(int s,int t){
F tot = 0;
while(bfs(s,t)){
while(F df = dfs(s,t,numeric_limits<F>::max()))tot+=df;
}
return tot;
}
};
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n,r,m;
cin>>n>>r>>m;
Dinic<int> ds;
int source = n, sink = n+1;
ds.init(n+2);
vector<int> a(r),b(r),c(r);
vector<int> sum(n);
vector mat(n,vector(n,0)),mat2(n,vector(n,0));
for(int i=0;i<r;i++){
cin>>a[i]>>b[i]>>c[i];
a[i]--;
b[i]--;
sum[a[i]]-=c[i];
sum[b[i]]+=c[i];
mat[a[i]][b[i]]=m-1-c[i];
mat[b[i]][a[i]]=m-1+c[i];
ds.ae(a[i],b[i],m-1-c[i]);
ds.ae(b[i],a[i],m-1+c[i]);
}
int tot=0;
for(int i=0;i<n;i++){
if(sum[i]<0)ds.ae(i,sink,-sum[i]);
else{
tot+=sum[i];
ds.ae(source,i,sum[i]);
}
}
if(ds.maxFlow(source,sink)!=tot){
cout<<"IMPOSSIBLE\n";
}else{
for(int i=0;i<n;i++){
for(auto j : ds.adj[i]){
if(j.to!=source && j.to!=sink){
mat[i][j.to]-=j.cap;
//cout<<i<<" "<<j.to<<" "<<j.cap<<"\n";
}
}
}
for(int i=0;i<r;i++){
cout<<c[i]+mat[a[i]][b[i]]<<"\n";
}
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3488kb
input:
10 23 3 2 10 1 2 6 1 6 9 1 7 9 1 6 7 1 3 6 1 1 3 1 1 6 2 6 10 1 2 9 1 4 9 2 4 7 2 3 10 2 3 9 1 6 8 1 7 8 2 3 5 1 5 9 1 8 9 2 3 8 2 1 5 2 1 4 1 5 10 2
output:
1 1 1 1 1 1 -2 -1 -2 -2 -1 2 -1 -2 1 2 1 1 2 -1 2 1 2
result:
ok correct plan
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3684kb
input:
100 1297 11 27 34 5 7 34 6 7 90 3 80 90 6 37 80 6 37 48 5 47 48 6 47 86 5 56 86 6 56 84 5 63 84 6 38 63 6 66 91 8 12 91 6 12 15 5 15 22 1 22 87 5 46 87 6 46 63 10 63 87 8 71 87 6 65 71 6 38 65 1 38 67 4 29 67 6 9 29 6 9 21 5 16 21 6 16 89 2 89 98 5 4 98 6 4 13 4 13 33 5 14 33 6 14 66 10 66 86 10 57 ...
output:
5 6 -10 6 6 -10 -5 5 6 5 6 -5 -7 -10 5 1 -10 -10 10 -10 3 6 -8 4 6 6 5 6 -10 5 3 4 5 1 -10 10 6 -10 3 7 -5 -10 8 5 6 5 5 6 6 -10 -10 5 6 -10 -10 3 5 6 5 -10 6 8 -10 -3 8 -10 -10 -4 5 6 6 -10 6 6 -10 -10 -10 -10 6 -6 6 -10 -4 6 7 5 5 -10 -6 5 -1 6 -10 -10 -7 6 -10 6 -10 5 -10 -10 -10 -10 -5 5 -10 1 -...
result:
wrong answer weight could not be 0