QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#187128 | #3855. Regional development | szhlg# | RE | 1ms | 3992kb | C++14 | 1.9kb | 2023-09-24 14:47:48 | 2023-09-24 14:47:49 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
int read(){
int f = 1,x = 0;
char c = getchar();
while(c > '9' || c < '0'){
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9'){
x = x * 10 + c - '0';
c = getchar();
}
return x * f;
}
const int maxn = 21005;
int s,t;
int n,r,m;
struct stu{
int to,nxt,w;
}se[maxn];
int hd[maxn],cnt = 1;
void jia(int x,int y,int z){
se[++cnt].to = y;
se[cnt].nxt = hd[x];
se[cnt].w = z;
hd[x] = cnt;
}
int du[maxn];
const int inf = 1e8;
int lv[maxn],cur[maxn];
bool bfs()
{
memset(lv,-1,sizeof(lv));
lv[s] = 0;
for(int i=1;i<=n + 2;++i) cur[i] = hd[i];
queue<int> q;
q.push(s);
while(!q.empty()){
int u = q.front();
q.pop();
for(int i=hd[u];i;i=se[i].nxt){
int v = se[i].to ;
int vv = se[i].w;
if(vv > 0 && lv[v] == -1){
lv[v] = lv[u] + 1;
q.push(v);
}
}
}
return lv[t] != -1;
}
int dfs(int p = s,int fl = inf)
{
if(p == t) return fl;
int rmn = fl;
for(int i=cur[p];i && rmn;i = se[i].nxt){
cur[p] = i;
int v = se[i].to ;
int vl = se[i].w;
if(vl > 0 && lv[v] == lv[p] + 1){
int c = dfs(v,min(vl,rmn));
rmn -= c;
se[i].w -= c;
se[i^1].w += c;
}
}
return fl - rmn;
}
int noi[maxn];
signed main()
{
n = read(),r = read(),m = read();
for(int i=1;i<=r;++i){
int x = read(),y = read(),z = read();
jia(x,y,0);
jia(y,x,1);
noi[i] = z;
du[y] += z;
du[x] -= z;
}
s = n + 1;
t = n + 2;
int qwq = 0;
for(int i=1;i<=n;++i){
du[i] /= m;
if(du[i] < 0){
jia(i,t,-du[i]);
jia(t,i,0);
}
if(du[i] > 0){
qwq += du[i];
jia(s,i,du[i]);
jia(i,s,0);
}
}
int ans = 0;
while(bfs()){
ans += dfs();
}
if(ans < qwq){
printf("IMPOSSIBLE");
return 0;
}
for(int i=1;i<=r;++i){
if(se[i*2].w == 1) printf("%lld\n",noi[i] - m);
else printf("%lld\n",noi[i]);
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3852kb
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:
-2 1 1 1 1 1 -2 2 1 1 -1 2 -1 -2 1 2 1 -2 2 -1 -1 1 2
result:
ok correct plan
Test #2:
score: 0
Accepted
time: 1ms
memory: 3888kb
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 -8 6 6 5 6 5 6 5 6 6 8 6 5 1 -6 -5 10 8 6 6 1 4 6 6 5 6 -9 5 -5 4 5 6 -1 10 6 6 5 7 6 6 8 5 6 5 5 6 6 5 6 5 6 1 6 3 5 6 5 5 6 8 9 6 8 5 6 5 -6 -5 6 5 6 6 5 6 5 6 6 5 6 5 10 6 7 5 5 -5 7 5 5 6 -5 5 5 6 6 6 -6 5 10 -6 5 6 6 5 5 -4 6 -5 5 5 8 5 -5 -6 5 5 5 -5 5 6 -9 -5 5 6 1 5 -5 5 5 5 6 9 -6 -5 -8...
result:
ok correct plan
Test #3:
score: 0
Accepted
time: 1ms
memory: 3888kb
input:
100 1272 18 39 40 14 39 95 4 21 95 14 12 21 14 12 82 16 28 82 14 17 28 14 17 67 5 35 67 14 11 35 1 11 67 15 17 58 4 58 80 4 28 80 14 28 77 3 25 77 10 22 25 14 22 54 4 13 54 14 13 99 4 86 99 14 86 89 16 21 89 14 21 62 4 16 62 14 16 81 4 76 81 14 56 76 1 28 56 14 28 47 4 19 47 14 19 91 4 22 91 14 13 2...
output:
14 4 14 14 -2 14 14 5 14 1 -3 4 4 -4 3 10 14 4 14 -14 14 16 14 4 14 -14 14 1 14 4 14 -14 -4 14 -14 4 14 14 -14 4 13 4 2 -4 4 4 14 4 17 14 4 4 -4 9 -4 4 14 14 17 4 4 14 4 4 4 14 14 4 4 14 14 -14 2 4 9 4 4 -4 10 4 4 -4 -17 14 11 14 -14 14 10 4 8 4 14 -8 14 -4 4 -4 4 14 4 4 14 4 17 -17 17 11 7 11 7 7 -...
result:
ok correct plan
Test #4:
score: 0
Accepted
time: 1ms
memory: 3992kb
input:
100 1350 3 22 75 2 22 50 2 22 35 1 25 35 2 42 76 2 39 42 2 36 39 2 14 36 2 14 33 1 33 72 1 54 72 2 54 73 1 5 73 2 45 92 2 23 92 2 23 26 2 26 62 1 6 62 1 22 86 1 24 86 2 7 24 2 7 55 2 20 39 2 20 73 1 27 73 2 27 68 1 24 68 2 24 98 1 8 98 2 8 33 1 3 33 2 1 3 1 3 97 1 83 97 2 83 90 1 38 90 2 38 86 1 21 ...
output:
-1 2 1 2 2 2 2 2 1 1 2 1 -1 -1 -1 2 1 -2 1 2 2 2 2 -2 -1 1 2 1 2 1 2 1 1 2 1 -1 1 1 2 2 1 1 2 1 1 1 2 1 2 2 1 2 2 1 2 1 1 1 2 2 1 1 2 1 2 -2 2 -1 1 -2 2 2 -2 2 1 2 1 2 2 2 2 -2 -1 2 -2 1 2 1 1 -1 1 1 2 -2 2 1 1 1 1 2 1 -1 1 1 2 1 1 1 1 -1 2 1 1 1 2 1 2 2 -2 2 -2 2 1 2 1 1 2 2 -2 -1 2 1 2 2 2 1 -2 1 ...
result:
ok correct plan
Test #5:
score: -100
Runtime Error
input:
1000 9780 26 39 260 1 215 260 25 215 483 1 483 801 1 801 977 1 379 977 25 316 379 25 316 732 1 474 732 25 183 474 25 177 183 25 177 788 1 525 788 25 525 909 1 51 909 25 51 565 1 203 565 25 203 353 1 353 655 8 655 814 1 814 999 1 305 999 25 52 305 25 52 978 20 839 978 25 646 839 25 536 646 25 536 571...