QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#35559 | #1454. Um nik's Algorithm | qingyu_orz | TL | 3571ms | 294996kb | C++ | 2.9kb | 2022-06-16 20:42:58 | 2022-06-16 20:42:58 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
namespace file_read{
namespace input_file_io{
char ib[1<<25],*ip1=ib,*ip2=ib;
inline char gc(){
#ifdef JohnAlfnov
return getchar();
#else
return (ip1==ip2&&(ip2=(ip1=ib)+fread(ib,1,1<<24,stdin)),ip1==ip2?EOF:*ip1++);
#endif
}
inline int read(){
int x=0;
char c=gc();
while(c<'0'||c>'9')c=gc();
while(c>='0'&&c<='9'){
x=(x<<3)+(x<<1)+(c^'0');
c=gc();
}
return x;
}
};
namespace output_file_io{
char ob[1<<23],*op=ob;
inline void pc(char c){
*op++=c;
}
void write(int x){
if(x<0){
pc('-');
x=-x;
}
if(x==0)pc('0');
static int number_stack[40];
int total_count=0;
while(x)number_stack[++total_count]=x%10,x/=10;
while(total_count){
pc(number_stack[total_count]+'0');
--total_count;
}
}
inline void final_write(){
fwrite(ob,op-ob,1,stdout);
}
};
using namespace input_file_io;
using namespace output_file_io;
};
using namespace file_read;
int n,S,T;
int hd[5000005],mw[5000005],l[5000005],pre[5000005];
int nxt[12000005],c[12000005],bb[12000005],tt[12000005],tot=1;
inline void addedge(int u,int v,int w,int bh){
if(!hd[u])hd[u]=++tot;
else nxt[mw[u]]=++tot;
mw[u]=tot;
c[tot]=w,bb[tot]=bh,tt[tot]=v;
}
int q[5000005];
bool bfs(){
for(int i=1;i<=n;++i)l[i]=1e9+7,pre[i]=hd[i];
l[S]=1;
int h=0,t=-1;
q[++t]=S;
while(h<=t){
int x=q[h++];
for(int i=hd[x];i;i=nxt[i]){
int v=tt[i];
if(c[i]==0)continue;
if(l[v]>l[x]+1){
l[v]=l[x]+1;
if(v==T)return 1;
q[++t]=v;
}
}
}
return 0;
}
int ans=0;
int dinic(int x,int rl){
if(x==T)return rl;
int he=0;
for(int i=pre[x];i;i=nxt[i]){
pre[x]=i;
if(c[i]==0)continue;
int v=tt[i];
if(l[v]!=l[x]+1)continue;
int ll=dinic(v,min(c[i],rl));
rl-=ll,he+=ll;
c[i]-=ll,c[i^1]+=ll;
if(!rl)return he;
}
return he;
}
bool vist[2000005];
int main(){
int aa=clock();
int n1=read(),n2=read(),m=read();
n=1+n1+n2+1;
S=1,T=n;
for(int i=1;i<=n1;++i)addedge(S,1+i,1,0),addedge(1+i,S,0,0);
for(int i=1;i<=n2;++i)addedge(1+n1+i,T,1,0),addedge(T,1+n1+i,0,0);
for(int t=1;t<=m;++t){
int u=read(),v=read();
addedge(1+u,1+n1+v,1,t);
addedge(1+n1+v,1+u,0,0);
}
for(int i=1;i<=19;++i){
if(!bfs())break;
if(1.0*(clock()-aa)/CLOCKS_PER_SEC>3.4)break;
ans+=dinic(S,INT_MAX);
}
write(ans),pc('\n');
for(int i=2;i<=1+n1;++i)for(int j=hd[i];j;j=nxt[j]){
if(c[j])continue;
int dd=tt[j];
if(dd<2+n1||dd>1+n+n1)continue;
vist[bb[j]]=1;
}
for(int i=1;i<=m;++i)if(vist[i])write(i),pc('\n');
final_write();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 24184kb
input:
3 2 4 1 1 2 1 3 1 3 2
output:
2 1 4
result:
ok answer: 2, maximum: 2
Test #2:
score: 0
Accepted
time: 2ms
memory: 24040kb
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: 0ms
memory: 24044kb
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 1 2 3 4 7 8 11 12 13 16 21 24 27 28 29 30 31 32 36 37 38 39 40 41 44 45 47 48 49 51 53 55 58 59 60 62 63 65 66 68 69 70 71 74 75 76 80 81 83 84 88 92 94 95 96 98 99 103 104 105 106 109 113 114 122 123 128 132 133 134 137 138 142 143 145 147 150 151 153 154 157 164 171 173 178 179 182 184 187 19...
result:
ok answer: 1000, maximum: 1000
Test #4:
score: 0
Accepted
time: 0ms
memory: 24124kb
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 96 155
result:
ok answer: 2, maximum: 2
Test #5:
score: 0
Accepted
time: 0ms
memory: 24012kb
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 4 5 6 7 10 11 12 15 16 18 21 22 23 25 29 30 31 33 38 39 42 43 44 45 46 48 49 50 52 53 54 58 59 60 61 62 65 66 67 69 73 74 75 76 77 78 80 82 84 87 88 90 91 92 93 94 96 97 99 100 103 104 105 106 108 111 112 113 114 117 121 122 123 124 125 126 128 129 130 131 132 133 135 137 139 140 143 144 146...
result:
ok answer: 540, maximum: 540
Test #6:
score: 0
Accepted
time: 3ms
memory: 24128kb
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 2 3 4 5 6 7 10 11 13 15 16 17 18 19 20 22 23 24 26 27 28 29 31 32 34 35 36 39 40 41 42 43 44 45 46 47 48 50 51 52 53 54 58 60 61 62 63 64 65 66 68 70 71 72 73 75 76 77 78 79 80 81 84 85 86 88 89 91 92 93 94 95 96 97 98 99 100 101 104 105 106 108 109 110 113 115 117 118 120 122 123 124 125 126 ...
result:
ok answer: 944, maximum: 944
Test #7:
score: 0
Accepted
time: 3571ms
memory: 294996kb
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:
1085442 1 2 4 7 9 10 12 13 14 18 19 22 23 25 27 29 30 31 33 34 35 36 38 39 40 42 43 44 45 46 48 55 56 57 58 59 60 61 62 63 65 66 67 68 69 71 72 73 74 75 77 78 79 81 83 87 88 89 90 91 92 93 95 96 97 99 100 102 103 105 107 109 110 111 114 116 119 120 121 123 124 125 128 129 130 131 132 133 134 135 136...
result:
ok answer: 1085442, maximum: 1088264
Test #8:
score: 0
Accepted
time: 3484ms
memory: 294836kb
input:
2000000 2000000 2000000 1286561 1611624 1028477 1867578 1642356 1162128 1032429 316462 618144 22363 1644873 1514932 508824 1230141 1889259 22840 30270 259129 1567969 462330 150124 1227115 393968 534541 1378415 770304 977805 1666010 1199878 1476793 1249634 243739 1232999 531436 1146447 1845344 478779...
output:
1085157 1 2 3 4 5 6 8 9 11 13 14 15 17 18 19 20 22 23 24 25 30 37 38 39 40 41 42 43 44 45 46 47 48 49 51 52 53 54 55 56 59 60 62 64 65 66 67 68 72 74 75 76 77 80 83 84 86 88 89 91 93 98 100 101 102 104 105 107 108 109 112 113 114 115 116 117 122 123 125 126 127 128 130 131 133 134 135 137 138 139 14...
result:
ok answer: 1085157, maximum: 1088048
Test #9:
score: -100
Time Limit Exceeded
input:
2000000 2000000 2000000 402689 127765 1065927 1753952 991609 1640904 1061308 533154 1552300 326545 1905312 1074675 1084722 1799678 51070 1470757 310696 763584 1965988 759275 246577 1374893 277285 408924 1692272 1856320 72026 1123575 1881487 1519767 1993052 1562521 575291 1507572 205452 248456 134621...