QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#419911#8591. ShopsFaisal-Saqib#0 163ms24492kbC++171.8kb2024-05-24 12:39:102024-05-24 12:39:10

Judging History

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

  • [2024-05-24 12:39:10]
  • 评测
  • 测评结果:0
  • 用时:163ms
  • 内存:24492kb
  • [2024-05-24 12:39:10]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=5e5+10;
const int P=17;
const int inf=1e18;
int dp1[N];
int dp2[N];
vector<pair<int,int>> ma[N];
bool vis[N];
char ans1[N];
bool cal[N];
bool cal1[N];
void dfs(int x,char c='B')
{
	vis[x]=1;
	ans1[x]=c;
	if(c=='B')
		c='D';
	else
		c='B';
	for(auto [w,y]:ma[x])
	{
		if(!vis[y])
		{
			dfs(y,c);
		}
	}
}
void dfs_down(int x){
	cal[x]=1;
	for(auto [w,y]:ma[x])
	{
		if(!cal[y])
		{
			dfs_down(y);
			if(ans1[y]!=ans1[x])
			{
				dp1[x]=min(dp1[x],w);
			}
			else
			{
				dp1[x]=min(dp1[x],w+dp1[y]);
			}
		}
	}
}
void dfs_up(int x){
	cal1[x]=1;
	for(auto [w,y]:ma[x])
	{
		if(!cal1[y])
		{
			if(ans1[y]!=ans1[x])
			{
				dp2[y]=min(dp2[y],w);
			}
			else
			{
				dp2[y]=min(dp2[y],w+min(dp1[y],dp2[y]));
			}
			dfs_up(y);
		}
	}
}
signed main()
{
	srand(time(0));
	int n,m;
	cin>>n>>m;
	for(int j=0;j<m;j++)
	{
		int x,y,c;
		cin>>x>>y>>c;
		ma[x].push_back({c,y});
		ma[y].push_back({c,x});
	}
	if(n>16)
	{
		exit(-1);
		// return;
	}
	for(int i=1;i<=n;i++)
		sort(begin(ma[i]),end(ma[i]));
	dfs(1);
	int ans=0;
	for(int v=1;v<=n;v++)
		dp1[v]=dp2[v]=inf;
	dfs_down(1);
	dfs_up(1);
	for(int v=1;v<=n;v++)
		ans=max(ans,min(dp1[v],dp2[v]));
	int val=ans;
	string ap;
	for(int j=1;j<=n;j++)
		ap+=ans1[j];
	for(int trap=1;trap<=n;trap++)
	{
		int x=trap;
		for(int j=1;j<=n;j++)
		{
			vis[j]=0;
			cal[j]=cal1[j]=0;
			dp1[j]=dp2[j]=inf;
		}
		ans=0;
		dfs(x);
		dfs_down(x);
		dfs_up(x);
		for(int v=1;v<=n;v++)
			ans=max(ans,min(dp1[v],dp2[v]));
		if(ans<val)
		{
			val=ans;
			ap="";
			for(int j=1;j<=n;j++)
				ap+=ans1[j];
		}
	}
	cout<<val<<endl;
	cout<<ap<<endl;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 7
Accepted
time: 3ms
memory: 16916kb

input:

3 3
1 2 3
2 3 1
1 3 2

output:

2
BBD

result:

ok inconveniences = 2

Test #2:

score: 7
Accepted
time: 5ms
memory: 16124kb

input:

5 6
3 2 3
4 2 1
5 3 9
1 3 5
1 4 2
2 3 1

output:

9
BBDDB

result:

ok inconveniences = 9

Test #3:

score: 7
Accepted
time: 76ms
memory: 21368kb

input:

8 135737
1 4 763713071
3 7 45141437
4 8 618418466
6 8 91803956
7 5 972595945
5 2 751163228
2 8 9886315
4 3 106470622
8 6 949495949
1 2 885918825
4 6 322040168
7 6 754489330
4 8 618968328
5 3 996860159
3 6 210132897
3 4 591744987
8 7 447985622
2 4 4833956
5 7 610154418
2 5 410116873
2 5 912717336
8 7...

output:

19258
BDBBDDBD

result:

ok inconveniences = 19258

Test #4:

score: 0
Wrong Answer
time: 163ms
memory: 24492kb

input:

13 265680
1 4 380374649
3 10 784226975
4 11 872278132
5 11 592626606
6 11 526829741
9 11 740573742
10 8 276205430
8 12 63494864
11 2 71771791
2 13 737308410
12 7 878733769
7 13 903269395
5 9 120579034
5 12 138606132
4 11 662866874
11 2 700788392
6 10 585492424
5 12 28226068
13 10 114889571
7 11 2004...

output:

70506
BDBBBBDDDBDDB

result:

wrong answer your claimed answer is 70506, but the inconveniences of your plan is actually 65982

Subtask #2:

score: 0
Runtime Error

Test #11:

score: 0
Runtime Error

input:

500000 499999
1 2 776715136
2 3 406881694
3 4 265792290
4 5 507607272
5 6 182246639
6 7 997847597
7 8 164130256
8 9 278962226
9 10 411194641
10 11 363646402
11 12 672225656
12 13 494629089
13 14 717664153
14 15 121619271
15 16 476857704
16 17 301215244
17 18 810217743
18 19 850722975
19 20 10710274
...

output:


result:


Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Runtime Error

Test #31:

score: 0
Runtime Error

input:

366489 397001
2 127909 1
7 171229 1
8 158597 1
11 282213 1
14 356007 1
15 286102 1
16 93205 1
17 260111 1
18 138962 1
20 359938 1
29 223905 1
31 357684 1
32 259968 1
34 65205 1
37 200276 1
41 83195 1
43 159858 1
48 332277 1
50 320322 1
51 338467 1
53 262785 1
55 83815 1
56 173198 1
58 169473 1
63 19...

output:


result:


Subtask #5:

score: 0
Skipped

Dependency #1:

0%