QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#454738 | #860. We apologize for any inconvenience | Nana7 | TL | 69ms | 7312kb | C++14 | 1.4kb | 2024-06-25 12:26:14 | 2024-06-25 12:26:15 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define I inline
#define inf 1e9
using namespace std;
const int N = 1510;
int f[N][N],a[N],b[N],ans[N];
int n,m;
I void out() {
}
I void trans(int x) {
for(int i=1;i<=m+n;++i)
for(int j=1;j<=m+n;++j)
f[i][j]=f[j][i]=min(f[i][j],f[i][x]+f[x][j]);
}
I int gans() {
int ret=0;
for(int i=1;i<=n;++i)
for(int j=1;j<=n;++j) {
if(f[i][j]==1e9) continue;
ret=max(ret,f[i][j]/2-1);
}
return ret;
}
I int read() {
int ret=0,w=1; char ch;
while((ch=getchar())>'9'||ch<'0'&&ch!='-'); if(ch=='-') w=-1; else ret=ch-'0';
while((ch=getchar())>='0'&&ch<='9') ret=ret*10+ch-'0';
return ret*w;
}
int main()
{
int T; cin>>T;
while(T--) {
cin>>n>>m;
for(int i=1;i<=m;++i) b[i]=0;
for(int i=1;i<=m+n;++i)
for(int j=1;j<=m+n;++j)
f[i][j]=inf;
for(int i=1;i<=n+m;++i) f[i][i]=0;
for(int i=1;i<=m;++i) {
int x; x=read();
for(int j=1;j<=x;++j) {
int y; y=read();
f[i+n][y]=f[y][i+n]=1;
}
}
//printf("%d\n",gans());
int q=read();
for(int i=1;i<=q;++i) a[i]=read(),b[a[i]]=1;
for(int i=1;i<=m;++i) if(!b[i]) trans(i+n);
for(int i=1;i<=n;++i) trans(i);
for(int i=q;i>=1;--i) {
ans[i]=gans();
trans(a[i]+n);
}
ans[0]=gans();
for(int i=0;i<=q;++i) printf("%d\n",ans[i]);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3872kb
input:
1 5 4 3 1 3 5 2 1 4 2 2 3 2 2 4 3 1 4 3
output:
1 2 0 0
result:
ok 4 number(s): "1 2 0 0"
Test #2:
score: 0
Accepted
time: 69ms
memory: 7312kb
input:
35 20 20 2 2 13 2 2 9 7 10 3 9 15 5 11 4 9 16 19 15 4 17 18 5 3 8 8 12 20 16 11 18 9 6 4 12 4 18 15 17 6 16 19 14 7 5 20 9 3 8 14 4 5 14 7 9 17 5 3 17 11 20 15 19 11 16 5 8 13 15 20 18 9 10 14 7 4 3 13 19 10 17 6 8 15 9 4 12 20 7 14 16 5 4 12 11 6 18 14 20 17 18 4 8 15 11 16 14 6 5 13 19 3 8 3 10 8 ...
output:
1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 1 1 0 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 1 0 0 0 0 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 2 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 1 1 1 0 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 0 0 0 ...
result:
ok 893 numbers
Test #3:
score: -100
Time Limit Exceeded
input:
2 750 750 2 47 500 2 51 145 2 22 531 2 22 354 2 22 727 2 25 700 2 7 159 2 42 356 2 57 727 2 28 237 2 57 714 2 68 511 2 29 81 2 65 318 2 43 91 2 65 488 2 68 549 2 16 310 2 30 618 2 6 105 2 7 468 2 34 253 2 51 155 2 21 205 2 22 470 2 36 642 2 17 649 2 66 229 2 10 409 2 65 105 2 21 395 2 51 552 2 25 55...