QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#94580 | #5870. A.I. War | eyiigjkn | 32 ✓ | 132ms | 4624kb | C++14 | 1.6kb | 2023-04-06 18:32:45 | 2023-04-06 18:32:46 |
Judging History
answer
# include <bits/stdc++.h>
using namespace std;
constexpr int INF=1e9;
int que[410],dis[410],f[2010],w1[410],w2[410][410];
vector<int> G[410],H[410];
bitset<401> st[410];
struct Edge
{
int u,v;
Edge(){}
Edge(int u,int v):u(u),v(v){}
bool operator<(const Edge &t)const{return dis[u]>dis[t.u];}
}E[2010];
inline void chkmax(int &x,const int &y){x=max(x,y);}
int main()
{
int T,n,m,u,v;
cin>>T;
for(int _=1;_<=T;_++)
{
int l=0,r=0,ans=0,tot=0;
scanf("%d%d",&n,&m);
for(int i=0;i<m;i++)
{
scanf("%d,%d",&u,&v);u++;v++;
G[u].push_back(v);
G[v].push_back(u);
st[u].set(v);st[v].set(u);
}
for(int i=1;i<=n;i++) w1[i]=st[i].count();
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
w2[i][j]=(st[i]&st[j]).count();
fill(dis+1,dis+n+1,INF);
dis[que[r++]=2]=0;
while(l<r)
{
int u=que[l++];
for(int v:G[u])
if(dis[u]+1<dis[v])
dis[que[r++]=v]=dis[u]+1;
}
for(int u=1;u<=n;u++)
for(int v:G[u])
if(dis[v]+1==dis[u])
E[++tot]=Edge(u,v);
sort(E+1,E+tot+1);
for(int i=1;i<=tot;i++) H[E[i].u].push_back(i);
fill(f+1,f+tot+1,-INF);
for(int i:H[1])
{
int u=E[i].u,v=E[i].v;
f[i]=w1[v]-w2[u][v];
}
for(int i=1;i<=tot;i++)
{
if(f[i]<=-INF) continue;
int u=E[i].u,v=E[i].v;
bool flag=0;
for(int j:H[v])
{
int w=E[j].v;
flag|=(w==2);
chkmax(f[j],f[i]+w1[w]-w2[u][w]-w2[v][w]+(st[u]&st[v]&st[w]).count());
}
if(flag) chkmax(ans,f[i]);
}
ans+=st[1].count();
printf("Case #%d: %d %d\n",_,dis[1]-1,ans-(dis[1]>1?dis[1]:0));
for(int i=1;i<=n;i++) G[i].clear(),H[i].clear(),st[i].reset();
}
return 0;
}
详细
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 4ms
memory: 3768kb
input:
50 2 1 0,1 3 3 0,1 1,2 0,2 5 5 0,4 0,2 2,4 1,2 1,4 7 9 0,6 0,2 0,4 2,4 3,4 2,3 3,5 4,5 1,5 5 5 3,4 1,4 0,2 0,3 1,2 28 147 9,27 14,27 5,18 5,25 14,17 15,20 10,24 13,21 11,26 1,13 0,10 0,14 5,21 10,27 5,20 1,9 11,24 10,22 7,27 5,23 7,25 10,18 8,23 8,20 12,27 7,22 1,4 11,18 14,21 0,8 15,23 9,24 6,23 11...
output:
Case #1: 0 1 Case #2: 0 2 Case #3: 1 2 Case #4: 2 4 Case #5: 1 2 Case #6: 3 22 Case #7: 1 19 Case #8: 3 32 Case #9: 3 5 Case #10: 1 2 Case #11: 12 18 Case #12: 6 11 Case #13: 3 15 Case #14: 3 14 Case #15: 3 27 Case #16: 1 12 Case #17: 1 12 Case #18: 3 17 Case #19: 0 11 Case #20: 3 20 Case #21: 3 15 ...
result:
ok 50 lines
Subtask #2:
score: 22
Accepted
Test #2:
score: 22
Accepted
time: 132ms
memory: 4624kb
input:
50 305 588 115,116 94,97 145,149 46,49 298,300 65,67 51,56 3,5 228,231 102,104 6,9 214,215 69,72 148,150 27,29 42,44 115,117 38,40 286,287 129,131 129,130 85,88 40,43 209,211 222,226 235,237 179,181 118,119 113,118 234,238 176,178 245,247 67,70 199,201 153,155 255,259 154,156 66,69 108,112 290,292 5...
output:
Case #1: 119 184 Case #2: 3 121 Case #3: 84 128 Case #4: 124 184 Case #5: 3 338 Case #6: 3 364 Case #7: 3 205 Case #8: 3 215 Case #9: 3 250 Case #10: 3 355 Case #11: 3 216 Case #12: 2 46 Case #13: 33 50 Case #14: 3 297 Case #15: 0 1 Case #16: 4 12 Case #17: 3 251 Case #18: 3 248 Case #19: 2 22 Case ...
result:
ok 50 lines
Extra Test:
score: 0
Extra Test Passed