QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#775083 | #2683. British Menu | zjc5 | WA | 5ms | 25636kb | C++14 | 1.9kb | 2024-11-23 14:40:40 | 2024-11-23 14:40:40 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=100010,M=6;
int n,m,a[N],b[N],dfn[N],low[N],cnt;
int st[N],tp,fa[N],ta[N],ct[N],dis[N][M][M];
int in[N],f[N][M],ans;
bool ins[N],bl[M];
vector<int>v[N];
struct node{
int t,b;
};
vector<node>tar[N][M];
queue<int>q;
void tarjan(int x){
dfn[x]=low[x]=++cnt;
st[++tp]=x;
ins[x]=1;
for(int t:v[x]){
if(!dfn[t]){
tarjan(t);
low[x]=min(low[x],low[t]);
}else if(ins[t])
low[x]=min(low[x],dfn[t]);
}
if(low[x]==dfn[x]){
int y;
while(1){
y=st[tp--];
fa[y]=x;
ins[y]=0;
ta[y]=++ct[x];
if(y==x) break;
}
}
}
void dfs(int st,int now,int d,int bel){
for(int t:v[now])
if(fa[t]==bel&&!bl[ta[t]])
if(d+1>dis[bel][st][ta[t]]){
dis[bel][st][ta[t]]=d+1;
bl[ta[t]]=1;
dfs(st,t,d+1,bel);
bl[ta[t]]=0;
}
}
int main(){
cin>>n>>m;
for(int i=1;i<=m;i++){
cin>>a[i]>>b[i];
v[a[i]].push_back(b[i]);
}
for(int i=1;i<=n;i++)
if(!dfn[i]) tarjan(i);
for(int i=1;i<=n;i++){
dis[fa[i]][ta[i]][ta[i]]=0;
bl[ta[i]]=1;
dfs(ta[i],i,0,fa[i]);
bl[ta[i]]=0;
}
for(int i=1;i<=m;i++){
int p=fa[a[i]],q=fa[b[i]];
if(p!=q){
tar[p][ta[a[i]]].push_back({q,ta[b[i]]});
in[q]++;
}
}
for(int i=1;i<=n;i++)
if(ct[i]&&!in[i]){
for(int j=1;j<=ct[i];j++) {
for(int k=1;k<=ct[i];k++)
f[i][j]=max(f[i][j],dis[i][k][j]+1);
}
q.push(i);
}
while(!q.empty()){
int d=q.front();
q.pop();
for(int j=1;j<=ct[d];j++){
int s=f[d][j]+1;
for(node k:tar[d][j]){
for(int p=1;p<=ct[k.t];p++)
f[k.t][p]=max(f[k.t][p],dis[k.t][k.b][p]+s);
in[k.t]--;
if(!in[k.t]) q.push(k.t);
}
}
}
for(int i=1;i<=n;i++)
for(int j=1;j<=ct[i];j++)
ans=max(ans,f[i][j]);
cout<<ans;
return 0;
}
/*
10 18
3 6
2 10
2 5
5 3
4 2
1 5
7 9
10 7
8 6
3 2
4 8
8 9
3 7
7 8
1 4
3 1
5 1
3 9
ans:9
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 25636kb
input:
10 6 7 8 4 2 8 6 5 1 4 1 4 5
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 0ms
memory: 25024kb
input:
10 10 1 3 8 9 6 10 1 2 7 9 10 9 5 1 2 5 8 6 7 8
output:
5
result:
ok single line: '5'
Test #3:
score: 0
Accepted
time: 2ms
memory: 23912kb
input:
10 8 7 6 4 2 10 6 4 5 2 4 3 2 6 10 2 1
output:
4
result:
ok single line: '4'
Test #4:
score: 0
Accepted
time: 0ms
memory: 24960kb
input:
10 19 3 6 9 10 7 9 9 8 8 7 5 6 3 8 6 9 5 9 2 6 6 8 1 4 6 7 6 10 3 9 10 7 4 9 10 8 1 8
output:
6
result:
ok single line: '6'
Test #5:
score: 0
Accepted
time: 0ms
memory: 25240kb
input:
10 19 2 7 8 10 9 8 3 10 8 9 4 5 2 10 1 8 9 6 1 9 4 6 3 2 5 9 5 2 10 7 5 10 7 6 6 9 4 7
output:
8
result:
ok single line: '8'
Test #6:
score: 0
Accepted
time: 0ms
memory: 23668kb
input:
10 18 3 6 2 10 2 5 5 3 4 2 1 5 7 9 10 7 8 6 3 2 4 8 8 9 3 7 7 8 1 4 3 1 5 1 3 9
output:
9
result:
ok single line: '9'
Test #7:
score: 0
Accepted
time: 0ms
memory: 22132kb
input:
12 11 11 10 12 10 8 12 9 12 5 7 1 6 8 11 9 11 7 9 7 11 2 9
output:
5
result:
ok single line: '5'
Test #8:
score: 0
Accepted
time: 0ms
memory: 22236kb
input:
7 7 1 2 2 3 3 4 4 5 5 6 6 2 4 7
output:
6
result:
ok single line: '6'
Test #9:
score: 0
Accepted
time: 5ms
memory: 23796kb
input:
9 9 1 2 2 3 3 4 4 5 5 6 6 2 4 7 8 1 9 8
output:
8
result:
ok single line: '8'
Test #10:
score: -100
Wrong Answer
time: 0ms
memory: 25312kb
input:
7 9 1 2 2 3 3 4 4 5 5 6 6 2 4 7 6 4 3 5
output:
6
result:
wrong answer 1st lines differ - expected: '7', found: '6'