QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#419910#8591. ShopsFaisal-Saqib#Compile Error//C++171.7kb2024-05-24 12:38:092024-05-24 12:38:10

Judging History

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

  • [2024-05-24 12:38:10]
  • 评测
  • [2024-05-24 12:38:09]
  • 提交

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 tp=1;tp<=n;tp++)
			ans=max(ans,dp[tp]);
		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

answer.code: In function ‘int main()’:
answer.code:111:37: error: ‘dp’ was not declared in this scope; did you mean ‘tp’?
  111 |                         ans=max(ans,dp[tp]);
      |                                     ^~
      |                                     tp