QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#87516 | #1454. Um nik's Algorithm | c20230139 | WA | 1229ms | 177708kb | C++14 | 1.8kb | 2023-03-13 15:53:50 | 2023-03-13 15:53:54 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int inf=0x3f3f3f3f,N=4e6+5,M=1e7+5;
//const int inf=0x3f3f3f3f,N=1e3+5,M=1e3+5;
int head[N],ver[M],edge[M],Next[M],d[N],id[N];
int s,t,tot=1,maxflow,flow;
void add(int x,int y,int z,int k) {
ver[++tot]=y,edge[tot]=z,Next[tot]=head[x],head[x]=tot,id[tot]=k;
ver[++tot]=x,edge[tot]=0,Next[tot]=head[y],head[y]=tot,id[tot]=0;
}
queue<int> q;
int bfs() {
for(int i=1;i<=t;i++)d[i]=0;
while(q.size())q.pop();
q.push(s),d[s]=1;
while(q.size()) {
int x=q.front();
q.pop();
for(int i=head[x];i;i=Next[i])
if(edge[i]&&!d[ver[i]]) {
q.push(ver[i]),d[ver[i]]=d[x]+1;
if(ver[i]==t)return 1;
}
}
return 0;//分层,判断是否可增广
}
int vis[N];
int dinic(int x,int flow) {
if(x==t) return flow;
int rest=flow,k;//rest现在还有多少可流
for(int i=head[x];i;i=Next[i])
if(edge[i]&&d[ver[i]]==d[x]+1) {//必须跳到下一层
k=dinic(ver[i],min(rest,edge[i]));
// if(!k) d[ver[i]]=0;
if(k) {
edge[i]-=k,edge[i^1]+=k,rest-=k;
vis[id[i]]=1;
vis[id[i^1]]=0;
if(!rest) return flow;
}
}
return flow-rest;//用了多少流
}
int main(){
int n1,n2,m;
scanf("%d%d%d",&n1,&n2,&m);
s=n1+n2+1;
t=s+1;
for(int i=1;i<=m;i++) {
int u,v;
scanf("%d%d",&u,&v);
add(u,v+n1,1,i);
}
for(int i=1;i<=n1;i++) {
add(s,i,1,0);
}
for(int i=1;i<=n2;i++) {
add(i+n1,t,1,0);
}
while(bfs()) while((flow=dinic(s,inf)))maxflow+=flow;
printf("%d\n",maxflow);
for(int i=1;i<=m;i++) {
if(vis[i]) {
printf("%d\n",i);
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3524kb
input:
3 2 4 1 1 2 1 3 1 3 2
output:
2 2 4
result:
ok answer: 2, maximum: 2
Test #2:
score: 0
Accepted
time: 2ms
memory: 3460kb
input:
20 20 20 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20
output:
20 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
result:
ok answer: 20, maximum: 20
Test #3:
score: 0
Accepted
time: 3ms
memory: 3920kb
input:
1000 1000 10000 988 405 844 805 40 354 416 591 520 704 697 24 315 386 122 390 991 213 506 14 309 298 26 829 329 63 787 91 971 703 805 699 624 645 121 181 841 741 473 84 258 116 490 753 725 603 265 302 869 71 611 507 59 292 11 532 117 61 192 600 650 342 204 580 687 675 670 407 637 622 569 236 728 476...
output:
1000 3 76 91 153 155 168 171 173 233 234 297 398 401 414 428 504 515 583 603 677 697 791 936 954 972 978 987 993 1009 1031 1056 1085 1197 1278 1280 1313 1331 1337 1350 1504 1516 1576 1590 1606 1665 1690 1703 1759 1768 1788 1794 1836 1894 1971 1977 1980 2014 2031 2042 2053 2069 2099 2118 2122 2132 21...
result:
ok answer: 1000, maximum: 1000
Test #4:
score: 0
Accepted
time: 2ms
memory: 3516kb
input:
100 2 200 40 1 22 2 75 2 79 1 27 2 11 1 7 1 64 1 21 1 57 2 47 1 4 2 61 2 37 1 8 2 32 2 84 1 63 1 67 1 86 2 88 2 73 1 17 1 94 2 44 2 19 2 16 1 33 2 92 1 24 2 100 2 18 2 85 1 7 2 43 1 82 2 15 2 88 1 91 1 65 1 69 1 36 1 6 2 23 2 58 1 59 1 64 2 38 1 72 1 99 1 76 1 11 2 2 2 98 1 66 2 77 1 47 2 98 2 52 2 ...
output:
2 116 150
result:
ok answer: 2, maximum: 2
Test #5:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
1000 1000 1000 411 789 753 186 495 203 417 324 490 424 195 480 314 23 663 218 12 747 124 390 134 38 218 536 291 840 174 908 474 767 313 167 575 9 857 427 313 27 959 935 258 70 472 957 747 228 205 939 293 303 626 802 712 283 658 346 208 383 889 204 99 640 801 966 828 742 534 11 259 734 226 129 843 35...
output:
540 1 2 3 5 6 7 11 17 18 21 22 25 31 33 34 37 41 42 43 44 45 46 49 50 52 55 58 60 62 63 66 67 70 74 76 78 80 84 85 86 88 89 90 92 94 95 96 97 100 103 107 111 113 114 117 119 120 121 122 125 129 130 131 143 148 149 150 151 154 155 157 160 161 162 163 165 166 167 168 169 173 175 178 179 192 195 196 19...
result:
ok answer: 540, maximum: 540
Test #6:
score: 0
Accepted
time: 2ms
memory: 3680kb
input:
1000 2000 3000 143 619 571 526 215 1074 6 1714 370 937 120 784 134 1671 722 1528 397 345 464 401 198 589 283 564 212 232 527 286 237 1649 413 1570 964 1731 194 645 639 735 182 656 641 1143 535 98 113 596 787 972 306 818 657 1202 321 1327 753 1088 122 1823 471 611 516 811 380 1548 872 973 509 1841 70...
output:
944 1 17 18 41 46 54 55 60 65 68 72 75 81 91 94 104 152 168 182 187 202 216 222 244 247 252 270 282 303 307 313 315 319 320 321 323 341 366 368 372 375 392 401 408 411 418 427 446 456 458 463 479 488 490 500 513 542 549 567 570 575 587 596 616 620 635 638 645 657 671 674 679 681 683 695 719 721 727 ...
result:
ok answer: 944, maximum: 944
Test #7:
score: -100
Wrong Answer
time: 1229ms
memory: 177708kb
input:
2000000 2000000 2000000 1203137 1030076 215220 238101 293102 491863 1260446 165178 1683989 1718181 1641329 1179380 708733 403707 1918936 574923 525651 11571 1169951 422281 1086376 303530 1286459 1692862 31854 394688 916288 273853 709758 1176923 1730408 1766172 1890708 588004 344339 283448 1676753 13...
output:
442383 4 1165719 1447953 1500004 1500005 1500006 1500008 1500009 1500010 1500011 1500012 1500013 1500014 1500015 1500016 1500017 1500018 1500021 1500022 1500023 1500024 1500025 1500026 1500028 1500031 1500032 1500033 1500034 1500035 1500036 1500037 1500038 1500039 1500043 1500044 1500047 1500048 150...
result:
wrong answer Duplicate vertex in the first part: 898686