QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#799537#9352. Highway BusesBINYUWA 8ms70412kbC++143.0kb2024-12-05 15:36:312024-12-05 15:36:31

Judging History

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

  • [2024-12-10 15:19:00]
  • hack成功,自动添加数据
  • (/hack/1277)
  • [2024-12-05 15:36:31]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:70412kb
  • [2024-12-05 15:36:31]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair <int,int>
#define pli pair <ll,int>
#define fi first
#define se second
const int N = 2e5,M = 50;
int n,m,T,u,v,cnt,a[N + 5],b[N + 5],f[N + 5],vis[N + 5],siz[N + 5];
ll c[N + 5],w[N + 5],d[N + 5],ans[N + 5],C[N + 5];
vector <int> e[N + 5],E[N + 5];
priority_queue <pli,vector <pli>,greater <pli> > q;
int dis[M + 5][N + 5],t1[M + 5],t2[N + 5];
vector <pii> c1[M + 5],c2[N + 5];
map <int,int> mp[N + 5];
struct DSU
{
	int f[N + 5];
	void init(int n)
	{
		for(int i = 1;i <= n;i++)f[i] = i;
	}
	int fnd(int x)
	{
		return x == f[x] ? x : f[x] = fnd(f[x]);
	}
	bool merge(int x,int y)
	{
		x = fnd(x);y = fnd(y);
		if(x == y)return 0;
		f[x] = y;
		return 1;
	}
}dsu;
int get_siz(int u,int fa)
{
	siz[u] = 1;
	for(auto v : e[u])
		if(!vis[v]&&v != fa)
			siz[u] += get_siz(v,u);
	return siz[u];
}
int get_root(int u,int fa,int Siz)
{
	int mx = Siz - siz[u],rt = -1;
	for(auto v : e[u])
		if(!vis[v]&&v != fa)
			mx = max(mx,siz[v]),
			rt = max(rt,get_root(v,u,Siz));
	if(mx * 2 <= Siz)return u;
	return rt;
}
void init(int st,int *dis,vector <pii> &c,int op)
{
	for(int i = 1;i <= n;i++)dis[i] = 0;
	queue <int> q;q.push(st);
	while(!q.empty())
	{
		int u = q.front();q.pop();
		c.push_back({dis[u],u});
		if(op)mp[st][u] = dis[u];
		for(auto v : e[u])
		{
			if(v != st&&!dis[v]&&!vis[v])
				dis[v] = dis[u] + 1,q.push(v);
		}
	}
}
int solve(int u)
{
	vis[u] = 1;init(u,dis[0],c2[u],1);
	for(auto v : e[u])
		if(!vis[v])
			f[solve(get_root(v,u,get_siz(v,u)))] = u;
	return u;
}
void dij(int x)
{
	for(int i = 1;i <= n;i++)C[i] = c[i] + w[i] * x,t1[i] = t2[i] = 0;
	memset(vis,0,sizeof(vis));
	q.push({0 + C[1],1});vis[1] = 1;
	while(!q.empty())
	{
		int u = q.top().second;q.pop();
		for(int i = 1;i <= cnt;i++)
		{
			while(t1[i] != c1[i].size())
			{
				int v = c1[i][t1[i]].second;
				if(c1[i][t1[i]].first + dis[i][u] > b[u])break;
				if(!vis[v])
					d[v] = d[u] + C[u],vis[v] = 1,
					q.push({d[v] + c[v],v});
				t1[i]++;
			}
		}
		int now = u;
		while(now)
		{
			while(t2[now] != c2[now].size())
			{
				int v = c2[now][t2[now]].second;
				if(c2[now][t2[now]].first + mp[now][u] > b[u])break;
				if(!vis[v])
					d[v] = d[u] + C[u],vis[v] = 1,
					q.push({d[v] + c[v],v});
				t2[now]++;
			}
			now = f[now];
		}
	}
	for(int i = 1;i <= n;i++)ans[i] = min(ans[i],d[i]);
}
int main()
{
	scanf("%d %d %d",&n,&m,&T);dsu.init(n);
	for(int i = 1;i <= n;i++)
		scanf("%d %lld %lld",&b[i],&c[i],&w[i]);
	for(int i = 1;i <= m;i++)
	{
		scanf("%d %d",&u,&v);
		e[u].push_back(v);
		e[v].push_back(u);
		if(dsu.merge(u,v))
			E[u].push_back(v),E[v].push_back(u);
		else a[++cnt] = u;
	}
	for(int i = 1;i <= cnt;i++)init(a[i],dis[i],c1[i],0);
	for(int i = 1;i <= n;i++)swap(E[i],e[i]);
	solve(get_root(1,0,get_siz(1,0)));
	memset(ans,0x3f,sizeof(ans));
	dij(0);dij(T - 1);
	for(int i = 1;i <= n;i++)cout<<ans[i]<<"\n";
}

詳細信息

Test #1:

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

input:

6 6 2
1 50 -40
1 2 100
2 1 100
2 4 100
3 1 100
1 1 100
1 2
2 3
3 4
4 2
2 5
6 1

output:

0
10
52
52
52
10

result:

ok 6 lines

Test #2:

score: -100
Wrong Answer
time: 8ms
memory: 70412kb

input:

500 540 1000000
1 831790353 70
3 624594642 -127
2 189318946 -92
1 858646508 320
4 76999645 671
4 780012318 880
2 51254764 -12
2 420182468 -333
3 314764053 -36
1 560114854 -419
2 484412868 -31
3 466851594 6
4 535326027 732
4 430602789 578
1 605236859 43
4 633715178 896
3 110060408 -9
4 878946915 -654...

output:

0
1615624558
1542544819
1662548163
1474648686
1539102708
1570810517
1615624558
1539102708
1615624558
1539102708
1496782021
1634729968
1539102708
1539102708
1539102708
1552487755
1542544819
1841411333
1542544819
1539102708
1615624558
1539102708
1510170699
1754364477
1680870556
1546066466
1518054248
1...

result:

wrong answer 2nd lines differ - expected: '1277292628', found: '1615624558'