QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#293072#7871. 命运zhouhuanyi35 61ms94392kbC++202.9kb2023-12-28 21:22:332023-12-28 21:22:33

Judging History

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

  • [2023-12-28 21:22:33]
  • 评测
  • 测评结果:35
  • 用时:61ms
  • 内存:94392kb
  • [2023-12-28 21:22:33]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#define N 500000
using namespace std;
int read()
{
	char c=0;
	int sum=0;
	while (c<'0'||c>'9') c=getchar();
	while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
	return sum;
}
struct reads
{
	int x,y,z;
	bool operator < (const reads &t)const
	{
		return z>t.z;	
	}
};
reads st[N+1];
struct node
{
	int x,y,d;
};
node dque[N+1],dque2[N+1];
int n,m,sk,s,top,top2,rt[N+1],rt2[N+1],rk[N+1],rk2[N+1],cnt,cnt2,cnt3;
long long ans;
int find(int x)
{
	if (rt[x]==x) return x;
	return find(rt[x]);
}
void unionn(int x,int y)
{
	if (rk[x]>rk[y]) swap(x,y);
	dque[++top]=(node){x,y,rk[y]},rk[y]=max(rk[y],rk[x]+1),rt[x]=y,cnt--;
	return;
}
void undo()
{
	rt[dque[top].x]=dque[top].x,rk[dque[top].y]=dque[top].d,top--,cnt++;
	return;
}
int find2(int x)
{
	if (rt2[x]==x) return x;
	return find2(rt2[x]);
}
void unionn2(int x,int y)
{
	if (rk2[x]>rk2[y]) swap(x,y);
	dque2[++top2]=(node){x,y,rk2[y]},rk2[y]=max(rk2[y],rk2[x]+1),rt2[x]=y,cnt2--;
	return;
}
void undo2()
{
	rt2[dque2[top2].x]=dque2[top2].x,rk2[dque2[top2].y]=dque2[top2].d,top2--,cnt2++;
	return;
}
struct seg
{
	struct node
	{
		int l,r;
		vector<reads>p;
	};
	node tree[(N<<2)+1];
	void build(int k,int l,int r)
	{
		tree[k].l=l,tree[k].r=r;
		if (l==r) return;
		int mid=(l+r)>>1;
		build(k<<1,l,mid),build(k<<1|1,mid+1,r);
		return;
	}
	void add(int k,int l,int r,reads d)
	{
		if (tree[k].l==l&&tree[k].r==r)
		{
			tree[k].p.push_back(d);
			return;
		}
		int mid=(tree[k].l+tree[k].r)>>1;
		if (r<=mid) add(k<<1,l,r,d);
		else if (l>=mid+1) add(k<<1|1,l,r,d);
		else add(k<<1,l,mid,d),add(k<<1|1,mid+1,r,d);
		return;
	}
	void solve(int k)
	{
		int rst=0,rst2=0,rst3=0;
		for (int i=0;i<tree[k].p.size();++i)
		{
			if (find(tree[k].p[i].x)!=find(tree[k].p[i].y)) unionn(find(tree[k].p[i].x),find(tree[k].p[i].y)),rst++;
			if (tree[k].p[i].x!=s&&tree[k].p[i].y!=s&&find2(tree[k].p[i].x)!=find2(tree[k].p[i].y)) unionn2(find2(tree[k].p[i].x),find2(tree[k].p[i].y)),rst2++;
			if (tree[k].p[i].x==s||tree[k].p[i].y==s) cnt3++,rst3++;
		}
		if (tree[k].l==tree[k].r)
		{
			if (cnt!=1||cnt2>sk||cnt3<sk)
			{
				if (!tree[k].l)
				{
					puts("nonnondayo");
					exit(0);
				}
				else
				{
					ans+=st[tree[k].l].z;
					if (tree[k].l!=m) add(1,tree[k].l+1,m,st[tree[k].l]);
				}
			}
			for (int i=1;i<=rst;++i) undo();
			for (int i=1;i<=rst2;++i) undo2();
			cnt3-=rst3;
			return;
		}
		solve(k<<1),solve(k<<1|1);
		for (int i=1;i<=rst;++i) undo();
		for (int i=1;i<=rst2;++i) undo2();
		cnt3-=rst3;
		return;
	}
};
seg T;
int main()
{
	cnt=n=read(),cnt2=n-1,m=read(),sk=read(),s=read(),T.build(1,0,m);
	for (int i=1;i<=n;++i) rt[i]=rt2[i]=i;
	for (int i=1;i<=m;++i) st[i].x=read(),st[i].y=read(),st[i].z=read();
	sort(st+1,st+m+1);
	for (int i=1;i<=m;++i) T.add(1,0,i-1,st[i]);
	T.solve(1),printf("%lld\n",ans);
	return 0;
}

详细

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 61ms
memory: 94392kb

input:

49277 49276 1 49277
1 2 2000
2 3 3000
2 4 4000
3 5 5000
3 6 6000
4 7 7000
1 8 8000
7 9 9000
1 10 10000
5 11 11000
4 12 12000
3 13 13000
13 14 14000
1 15 15000
7 16 16000
11 17 17000
2 18 18000
10 19 19000
6 20 20000
4 21 21000
17 22 22000
1 23 23000
14 24 24000
4 25 25000
16 26 26000
15 27 27000
9 2...

output:

1214136002000

result:

ok single line: '1214136002000'

Test #2:

score: 0
Accepted
time: 23ms
memory: 83092kb

input:

49324 49323 1 49324
1 2 2
2 3 3
2 4 4
3 5 5
4 6 6
6 7 7
2 8 8
2 9 9
4 10 10
6 11 11
9 12 12
4 13 13
8 14 14
8 15 15
7 16 16
11 17 17
15 18 18
2 19 19
10 20 20
19 21 21
14 22 22
16 23 23
20 24 24
23 25 25
3 26 26
2 27 27
8 28 28
11 29 29
20 30 30
15 31 31
16 32 32
19 33 33
29 34 34
5 35 35
21 36 36
1...

output:

nonnondayo

result:

ok single line: 'nonnondayo'

Test #3:

score: 0
Accepted
time: 24ms
memory: 88252kb

input:

49423 49422 1 1
1 2 2
2 3 3
1 4 4
3 5 5
2 6 6
1 7 7
1 8 8
7 9 9
3 10 10
3 11 11
5 12 12
3 13 13
9 14 14
10 15 15
13 16 16
5 17 17
9 18 18
12 19 19
17 20 20
4 21 21
5 22 22
12 23 23
21 24 24
21 25 25
11 26 26
17 27 27
21 28 28
18 29 29
17 30 30
2 31 31
21 32 32
28 33 33
17 34 34
31 35 35
11 36 36
8 3...

output:

nonnondayo

result:

ok single line: 'nonnondayo'

Test #4:

score: 0
Accepted
time: 19ms
memory: 88016kb

input:

49501 49500 49501 49501
1 2 2
1 3 3
3 4 4
2 5 5
5 6 6
1 7 7
6 8 8
5 9 9
6 10 10
5 11 11
2 12 12
12 13 13
13 14 14
8 15 15
13 16 16
5 17 17
9 18 18
9 19 19
9 20 20
14 21 21
18 22 22
16 23 23
7 24 24
1 25 25
7 26 26
1 27 27
15 28 28
22 29 29
20 30 30
12 31 31
4 32 32
16 33 33
22 34 34
11 35 35
27 36 3...

output:

nonnondayo

result:

ok single line: 'nonnondayo'

Subtask #2:

score: 0
Wrong Answer

Test #5:

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

input:

21 20 2 21
1 2 18581
1 3 9620
2 4 4362
1 5 7702
5 6 17435
4 7 11679
3 8 14832
1 9 15073
2 10 6595
5 11 19676
11 12 16943
12 13 5268
5 14 20262
8 15 8192
7 16 12340
7 17 1437
7 18 3064
2 19 10437
12 20 2882
19 21 13483

output:

nonnondayo

result:

ok single line: 'nonnondayo'

Test #6:

score: 0
Accepted
time: 7ms
memory: 77576kb

input:

10 20 4 3
1 2 18247
2 3 9041
2 4 4031
2 5 7363
3 6 17172
1 7 11014
6 8 14781
8 9 15347
8 10 6598
5 9 19331
3 10 16523
10 6 5732
2 3 20357
6 9 8827
10 3 12864
6 3 1551
5 6 3932
3 1 10223
9 3 2296
8 5 13620

output:

54418

result:

ok single line: '54418'

Test #7:

score: -10
Wrong Answer
time: 3ms
memory: 77048kb

input:

10 20 6 10
1 2 18401
2 3 9843
3 4 4219
4 5 7552
4 6 17751
4 7 11318
5 8 14774
8 9 15541
5 10 6928
6 10 19860
10 5 16699
5 8 5937
5 2 20611
1 8 8077
10 1 12386
9 4 1663
9 10 3910
1 9 10401
7 10 2383
2 9 13681

output:

83828

result:

wrong answer 1st lines differ - expected: 'nonnondayo', found: '83828'

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 20
Accepted

Dependency #1:

100%
Accepted

Test #14:

score: 20
Accepted
time: 59ms
memory: 91384kb

input:

49997 54855 3516 1
3 2 123052288
4 2 96660489
5 4 21916339
6 4 110026562
7 2 37432698
8 4 38560777
9 5 83209343
10 9 80352789
11 2 88956732
12 7 65449905
13 2 38239108
14 5 90154247
15 4 30810782
16 13 96492679
17 14 112886179
18 9 87190321
19 5 91181643
20 3 107304129
21 15 101439791
22 19 12060197...

output:

2688197428747

result:

ok single line: '2688197428747'

Test #15:

score: 0
Accepted
time: 51ms
memory: 92876kb

input:

49997 51737 2558 1
3 2 123053094
4 2 96661142
5 4 21916374
6 3 110026590
7 3 37432598
8 5 38561207
9 3 83209496
10 6 80352500
11 10 88956702
12 8 65450072
13 7 38238198
14 6 90153662
1 2 30811464
16 15 96493667
17 15 112885786
18 16 87189617
19 16 91182345
20 19 107304693
21 16 101440408
22 19 12060...

output:

2837250649688

result:

ok single line: '2837250649688'

Test #16:

score: 0
Accepted
time: 28ms
memory: 84724kb

input:

49991 50261 391 1
3 2 123052091
4 2 96661422
5 4 21916293
6 3 110026296
7 2 37432814
8 6 38560644
9 5 83209409
10 8 80352817
11 5 88956822
12 2 65449972
13 9 38239183
14 12 90154124
15 6 30811280
16 10 96493604
17 15 112886136
18 2 87190273
19 15 91182250
20 8 107304418
21 5 101440651
22 8 120601454...

output:

nonnondayo

result:

ok single line: 'nonnondayo'

Subtask #5:

score: 10
Accepted

Test #17:

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

input:

49996 50165 184 1
3 2 123052595
4 3 96661399
5 2 21916499
6 3 110026337
7 6 37432710
8 2 38560107
9 8 83209370
10 8 80352229
11 2 88957425
12 7 65449321
13 5 38238243
14 5 90153912
15 11 30810953
16 3 96492912
17 13 112885611
18 15 87190336
19 9 91182003
20 2 107304872
21 6 101440738
22 13 120601711...

output:

2902613721568

result:

ok single line: '2902613721568'

Test #18:

score: 0
Accepted
time: 18ms
memory: 83084kb

input:

50000 50178 299 1
3 2 123053073
4 2 96660633
5 3 21916772
6 5 110026921
7 2 37432864
8 4 38561246
9 3 83208661
10 9 80352023
11 5 88956707
12 4 65449462
13 11 38238637
14 9 90154366
15 11 30811612
16 3 96492654
17 2 112885858
18 12 87189668
19 9 91182185
20 2 107304880
21 14 101440435
22 20 12060169...

output:

nonnondayo

result:

ok single line: 'nonnondayo'

Test #19:

score: 0
Accepted
time: 45ms
memory: 89816kb

input:

49995 50087 119 1
3 2 123052834
4 2 96661264
5 2 21915970
6 2 110026190
7 6 37432674
8 5 38560833
9 4 83209622
10 3 80352174
11 7 88957586
12 11 65449265
13 8 38238650
14 13 90154332
15 6 30811223
16 3 96493604
17 8 112885782
18 10 87190407
19 18 91182347
20 2 107304278
21 7 101440830
22 5 120602339...

output:

2907329109512

result:

ok single line: '2907329109512'

Subtask #6:

score: 0
Skipped

Dependency #3:

0%

Subtask #7:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%