QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#134805#4162. 所驼门王的宝藏osky12345680 116ms128288kbC++142.6kb2023-08-04 23:29:512023-08-04 23:29:53

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-04 23:29:53]
  • 评测
  • 测评结果:80
  • 用时:116ms
  • 内存:128288kb
  • [2023-08-04 23:29:51]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<set>
#include<ctime>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#define inf 1000000000
#define ll long long 
using namespace std;
int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int xx[8]={0,0,1,1,1,-1,-1,-1},yy[8]={1,-1,0,1,-1,0,1,-1};
int K,n,m,cnt,ind,scc,top,ans;
int last[100005],last2[100005];
int x[100005],y[100005],opt[100005];
int bl[100005],low[100005],dfn[100005],num[100005],q[100005];
int deep[100005];
bool mark[100005];
vector<int> a[1000005],b[1000005];
map<int,int> mp[1000005];
struct edge{
	int to,next;
}e[1000005],ed[1000005];
void insert(int u,int v)
{
	if(u==v)return;
	e[++cnt].to=v;e[cnt].next=last[u];last[u]=cnt;
}
void insert2(int u,int v)
{
	ed[++cnt].to=v;ed[cnt].next=last2[u];last2[u]=cnt;
}
void build()
{
	for(int i=1;i<=n;i++)
	{
		int x=0,t=a[i].size();
		for(int j=0;j<t;j++)
			if(opt[a[i][j]]==1){x=a[i][j];break;}
		for(int j=0;j<t;j++)
		{
			insert(x,a[i][j]);
			if(opt[a[i][j]]==1)insert(a[i][j],x);
		}
	}
	for(int i=1;i<=m;i++)
	{
		int x=0,t=b[i].size();
		for(int j=0;j<t;j++)
			if(opt[b[i][j]]==2){x=b[i][j];break;}
		for(int j=0;j<t;j++)
		{
			insert(x,b[i][j]);
			if(opt[b[i][j]]==2)insert(b[i][j],x);
		}
	}
	for(int i=1;i<=K;i++)
		if(opt[i]==3)
			for(int k=0;k<8;k++)
			{
				int t=mp[x[i]+xx[k]][y[i]+yy[k]];
				if(t)insert(i,t);
			}
}
void tarjan(int x)
{
	low[x]=dfn[x]=++ind;
	q[++top]=x;mark[x]=1;
	for(int i=last[x];i;i=e[i].next)
		if(!dfn[e[i].to])
		{
			tarjan(e[i].to);
			low[x]=min(low[x],low[e[i].to]);
		}
		else if(mark[e[i].to])
			low[x]=min(low[x],dfn[e[i].to]);
	if(low[x]==dfn[x])
	{
		int now=0;scc++;
		while(now!=x)
		{
			now=q[top--];mark[now]=0;
			bl[now]=scc;num[scc]++;
		}
	}
}
void rebuild()
{
	cnt=0;
	for(int x=1;x<=K;x++)
	{
		for(int i=last[x];i;i=e[i].next)
			if(bl[x]!=bl[e[i].to])
				insert2(bl[x],bl[e[i].to]);
	}
}
void dp(int x)
{
	mark[x]=1;
	for(int i=last2[x];i;i=ed[i].next)
	{
		if(!mark[ed[i].to])dp(ed[i].to);
		deep[x]=max(deep[x],deep[ed[i].to]);
	}
	deep[x]+=num[x];
	ans=max(deep[x],ans);
}
int main()
{
	K=read();n=read();m=read();
	for(int i=1;i<=K;i++)
	{
		x[i]=read(),y[i]=read(),opt[i]=read();
		mp[x[i]][y[i]]=i;
		a[x[i]].push_back(i);
		b[y[i]].push_back(i);
	}
	build();
	for(int i=1;i<=K;i++)
		if(!dfn[i])tarjan(i);
	rebuild();
	for(int i=1;i<=scc;i++)
		if(!mark[i])dp(i);
	printf("%d\n",ans);
	return 0;
}

詳細信息

Test #1:

score: 10
Accepted
time: 4ms
memory: 99964kb

input:

16 20 20
5 6 2
16 6 2
11 6 3
12 7 1
12 12 2
4 6 1
1 12 2
2 12 3
4 10 1
3 12 1
3 2 3
10 12 3
4 12 3
16 12 3
3 1 1
3 14 1

output:

12

result:

ok single line: '12'

Test #2:

score: 10
Accepted
time: 8ms
memory: 102032kb

input:

300 1000 1000
961 867 3
961 868 1
961 189 1
961 68 3
961 140 2
29 140 1
961 218 3
961 217 1
961 3 1
70 140 1
961 135 2
961 7 3
103 135 3
29 33 1
163 140 1
960 868 2
961 181 1
247 140 1
961 69 2
247 215 3
29 213 3
29 55 1
163 290 3
131 140 1
29 186 3
70 75 3
961 133 1
29 68 3
163 22 1
29 279 3
960 6 ...

output:

186

result:

ok single line: '186'

Test #3:

score: 10
Accepted
time: 11ms
memory: 104100kb

input:

500 100000 100000
15043 25566 3
15044 25566 1
15042 25567 3
15043 25565 2
15042 25566 3
15043 25568 2
15042 25568 3
15041 25565 1
15044 104 2
168 25565 3
15044 491 1
15044 81 3
168 25564 1
235 104 3
15042 25565 1
15041 25566 2
15044 469 3
15044 25567 1
15044 330 1
175 25566 3
146 104 3
15043 25567 3...

output:

275

result:

ok single line: '275'

Test #4:

score: 10
Accepted
time: 12ms
memory: 104468kb

input:

2500 5000 5000
3360 701 3
3361 700 3
3359 701 3
3359 700 3
3360 700 1
3361 699 2
3358 701 1
3358 700 3
3358 699 1
2447 699 2
3358 1086 3
3358 1615 1
3362 700 1
3362 1465 1
3362 1798 2
3362 699 3
3357 1087 3
3362 1261 3
3360 702 3
3361 701 2
3359 703 3
499 699 2
3358 702 3
3358 1087 3
3361 698 3
210 ...

output:

1346

result:

ok single line: '1346'

Test #5:

score: 10
Accepted
time: 78ms
memory: 120776kb

input:

50000 5000 5000
3607 4830 3
4313 4830 1
4626 4830 3
1386 4830 3
4641 4830 1
1512 4830 3
402 4830 2
2934 4830 2
401 4831 1
4626 4584 1
4386 4831 3
4641 2551 1
3557 4830 1
2491 4830 3
2334 4584 3
3556 4831 3
4387 4831 3
3607 3496 3
4626 4601 3
4626 2217 3
3556 4830 3
3556 4786 3
4364 3496 3
402 1201 2...

output:

10397

result:

ok single line: '10397'

Test #6:

score: 10
Accepted
time: 68ms
memory: 117032kb

input:

50000 1000000 1000000
20363 13775 3
10221 13775 3
10221 13969 3
10221 29039 3
10221 27851 3
654 13775 3
10649 29039 3
10221 22361 3
10649 8092 3
10648 8092 3
10649 24920 3
10221 25255 3
10220 25254 3
10221 17082 3
10222 13968 3
32129 27851 3
10221 23924 3
4819 29039 3
10222 13776 3
654 27930 3
10220...

output:

3256

result:

ok single line: '3256'

Test #7:

score: 10
Accepted
time: 116ms
memory: 128288kb

input:

80000 1000000 1000000
29977 11241 3
29977 15584 3
29977 375 3
29977 3093 3
29977 31245 2
25192 15584 3
29978 31246 1
29977 23943 2
29431 31245 3
25192 2098 3
29976 374 1
7181 375 3
29977 22345 3
29979 31246 3
5598 31245 3
29977 17843 3
29431 31246 2
29976 31244 3
17885 374 3
29976 31061 3
29977 3124...

output:

18588

result:

ok single line: '18588'

Test #8:

score: 10
Accepted
time: 52ms
memory: 114060kb

input:

100000 1000000 1000000
19362 10998 2
17887 10998 2
17887 691 2
17887 18793 2
19362 22537 1
17887 18792 1
19362 23192 2
19362 9406 2
19362 10999 1
17887 21103 1
19362 2323 2
17887 1781 2
19362 12326 1
7225 23192 1
8952 1781 1
17887 8534 1
19362 2725 2
17887 6665 1
17887 14381 1
19362 26932 1
22259 18...

output:

77333

result:

ok single line: '77333'

Test #9:

score: 0
Memory Limit Exceeded

input:

100000 1000000 1000000
14954 14897 3
14954 23720 2
28995 14897 2
26335 14897 3
26334 14897 2
21984 14897 3
26334 13037 3
14955 14896 3
26333 13037 2
26334 31550 2
26333 14897 3
26335 18761 3
26333 14369 3
26333 16092 3
28994 14898 3
26334 18762 3
21983 14898 3
26333 31709 1
26335 14898 3
14954 8301 ...

output:


result:


Test #10:

score: 0
Memory Limit Exceeded

input:

100000 1000000 1000000
10588 4708 3
10588 28735 3
10588 28736 3
10587 4709 3
10588 20418 3
10586 4709 3
10586 17297 2
10586 26967 3
10587 17296 3
7718 17297 3
7576 17296 3
7718 3553 3
25009 17296 3
25008 17297 3
7719 3552 2
10587 14985 3
10586 24976 3
10588 16895 2
10588 11593 1
10587 14986 3
6611 3...

output:


result: