QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#757578#2683. British Menuwjy2020WA 6ms44720kbC++113.2kb2024-11-17 10:50:392024-11-17 10:50:40

Judging History

你现在查看的是最新测评结果

  • [2024-11-17 10:50:40]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:44720kb
  • [2024-11-17 10:50:39]
  • 提交

answer

#include<bits/stdc++.h>
#define sfor(i,j,k) for(register int i=j;i<=k;++i)
#define dfor(i,j,k) for(register int i=k;i>=j;--i)
using namespace std;
#define int long long 
int dfn[6200005],low[6200005],dep,lf[6200005];
bool visitt[6200005];//q即桥 
int color[6200005],ct=0,bl[6200005];
int nnext[6200005],tto[6200005],edge[6200005],sta[6200005],llast[6200005],ttot=0;
void add(int inn,int jnn)
  {nnext[++ttot]=llast[inn];
   sta[ttot]=inn;
   tto[ttot]=jnn;
   llast[inn]=ttot;
  }//建图
vector <int> vv[500005],ed[500005];
int zhan[6200005],tail=0;
bool iz[6200005]; 
void tarjan(int u, int fa) {
	if(dfn[u]) return;
	low[u] = dfn[u] = ++dep;
	zhan[++tail] = u;
	iz[u]=1;
	for(int i = llast[u]; i; i = nnext[i]) {
	  if(!visitt[i])
	    {tarjan(tto[i],u);
	     if(iz[tto[i]])
	     low[u]=min(low[u],low[tto[i]]);}}
	if(dfn[u]==low[u])
	    {ct++;
		while(zhan[tail+1]!=u)
	        {//cout<<zhan[tail]<<" "<<u<<endl;
			vv[ct].push_back(zhan[tail]);
			iz[zhan[tail]]=0;
			bl[zhan[tail]]=ct;
			color[zhan[
			tail--]]=ct;}
		}
}//经典tarjan 
bool ctt[6200005];
int dis[100005][5][5];
bool ca[120005];
void dfs(int b,int st,int now,int ns,int di)
  {dis[b][st][now]=max(dis[b][st][now],di);
   int y=ns;
   sfor(j,0,vv[b].size()-1) ca[vv[b][j]]=1;
   sfor(i,1,di) ca[vv[b][y%5]]=0,y/=5;
//   cout<<st<<" "<<ns<<" "<<ca[0]<<" "<<ca[0]<<" "<<ca[1]<<" "<<ca[2]<<" "<<ca[3]<<endl;
   for(int i=llast[vv[b][now]];i;i=nnext[i])
     if(ca[tto[i]])
       sfor(j,0,4)
         if(vv[b][j]==tto[i])
	       dfs(b,st,j,ns*5+j,di+1);
   sfor(j,0,vv[b].size()-1) ca[vv[b][j]]=0;
   return;
  }
queue <int> q;
int cd[1200005],ans[1200005];
signed main()
{
int n,m,inn,jnn,knn;
cin>>n>>m;
for(int i=1;i<=m;i++)
  {cin>>inn>>jnn;//>>knn
   add(inn,jnn);//,knn
  }
for(int i=1;i<=n;i++)
  if(!dfn[i])  
	tarjan(i,0);
for(int i=1;i<=n;i++)
  if(!ctt[bl[i]])
     {ctt[bl[i]]=1;
//	  for(int j=0;j<vv[bl[i]].size();j++)
//	    {cout<<vv[bl[i]][j]<<" ";
//	    }cout<<endl;
	  for(int j=0;j<vv[bl[i]].size();j++) dfs(bl[i],j,j,j,1);
//	  cout<<bl[i]<<"IG"<<endl;
//	  for(int j=0;j<vv[bl[i]].size();j++){
//	    for(int k=0;k<vv[bl[i]].size();k++)
//	      cout<<dis[bl[i]][j][k]<<" ";cout<<endl;}
//	  cout<<endl;
     }
sfor(i,1,m)
  if(bl[sta[i]]!=bl[tto[i]])
    {cd[bl[sta[i]]]++;
     ed[bl[tto[i]]].push_back(i);
	}
sfor(i,1,ct) if(cd[i]==0) q.push(i);
while(!q.empty())
  {int x=q.front();q.pop();
   if(ed[x].size())
     sfor(i,0,ed[x].size()-1) {
	   cd[bl[sta[ed[x][i]]]]--;
	   if(!cd[bl[sta[ed[x][i]]]]) q.push(bl[sta[ed[x][i]]]);
      }
   sfor(i,0,vv[x].size()-1) ans[vv[x][i]]=vv[x].size();
   sfor(i,0,vv[x].size()-1)
     {int gh=0;
      for(int j=llast[vv[x][i]];j;j=nnext[j])
        if(bl[tto[j]]!=x) gh=max(gh,ans[tto[j]]);
//      cout<<x<<" "<<vv[x][i]<<" "<<gh<<"IB"<<endl;
      sfor(j,0,vv[x].size()-1)
	    {//cout<<ans[vv[x][j]]<<" "<<dis[x][j][i]<<"IH"<<endl;
		 ans[vv[x][j]]=max(ans[vv[x][j]],gh+dis[x][j][i]);
		}
	 }
  }
//sfor(i,1,n) cout<<"DIS "<<i<<" "<<ans[i]<<endl;
int ma=-1;
sfor(i,1,n) ma=max(ma,ans[i]);
cout<<ma<<endl;
return 0;
}
/*
15 16
15 14
14 13
13 12
12 1
1 2
2 3
3 4
4 5
5 1
2 6
6 7
7 8
8 9
9 10
10 11
11 7
*/

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 42420kb

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: 44720kb

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: 0ms
memory: 42476kb

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: 6ms
memory: 44524kb

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: 42424kb

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: -100
Wrong Answer
time: 5ms
memory: 44688kb

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:

8

result:

wrong answer 1st lines differ - expected: '9', found: '8'