QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#799895#9352. Highway BusesBINYUWA 0ms137036kbC++145.6kb2024-12-05 19:25:292024-12-05 19:25:29

Judging History

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

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

answer

#include<bits/stdc++.h>
using namespace std;
struct IO {
    static const int inSZ = 1 << 17;
    char inBuf[inSZ], *in1, *in2;
    template<class T> inline __attribute((always_inline))
    T read() {
        if (in1 > inBuf + inSZ - 32) [[unlikely]] {
            auto len = in2 - in1;
            memcpy(inBuf, in1, len);
            in1 = inBuf, in2 = inBuf + len;
            in2 += fread(in2, 1, inSZ - len, stdin);
            if (in2 != inBuf + inSZ) *in2 = 0;
        }
        T res = 0;
        unsigned char c;
        bool neg = 0;
        while ((c = *in1++) < 48) neg = c == 45;
        while (res = res * 10 + (c - 48), (c = *in1++) >= 48);
        return neg ? -res : res;
    }
    static const int outSZ = 1 << 21;
    char outBuf[outSZ], *out;
    template<class T> inline __attribute((always_inline))
    void write(T x) {
        if (out > outBuf + outSZ - 32) [[unlikely]]
        {
            fwrite(outBuf, 1, out - outBuf, stdout), out = outBuf;
		}
        if (!x) return *out++ = 48, void();
        if (x < 0) *out++ = 45, x = -x;
        alignas(2) const char* digits =
        "0001020304050607080910111213141516171819"
        "2021222324252627282930313233343536373839"
        "4041424344454647484950515253545556575859"
        "6061626364656667686970717273747576777879"
        "8081828384858687888990919293949596979899";
        alignas(64) static char buf[20];
        char* p = buf + 20;
        while (x >= 10) memcpy(p -= 2, digits + x % 100 * 2, 2), x /= 100;
        if (x) *--p = 48 + x;
        auto len = buf + 20 - p;
        memcpy(out, p, len), out += len;
    }
    void init() {
        in1 = in2 = inBuf + inSZ;
        out = outBuf;
    }
    ~IO() { fwrite(outBuf, 1, out - outBuf, stdout); }
} IO;
template<class T = int> inline T read() {
    return IO.read<T>();
}
template<class T> inline void print(T x, char c) {
    IO.write(x), *IO.out++ = c;
}
template<class T> inline void print(T x) {
    IO.write(x);
}
inline __attribute((always_inline)) void printCh(char c) {
    *IO.out++ = c;
}
#define pii pair <int,int>
#define pli pair <ll,int>
#define fi first
#define se second
#define ll long long
const int N = 2e5,M = 50;
int n,m,u,v,cnt,a[N + 5],b[N + 5],f[N + 5],vis[N + 5],siz[N + 5];
int Dis[N + 5],dis[M + 5][N + 5],t1[M + 5],t2[N + 5];
ll T,c[N + 5],w[N + 5],C[N + 5];
int d[N + 5],ans[N + 5];
priority_queue <pli,vector <pli>,greater <pli> > q;
queue <int> Q;
struct edge
{
	int v,nxt;
}e[2 * N + 5];
int head[N + 5],cnte;
struct Edge
{
	int v,nxt;
}E[2 * N + 5];
int Head[N + 5],cntE;
void adde(int u,int v)
{
	e[++cnte] = {v,head[u]};head[u] = cnte;
}
void addE(int u,int v)
{
	E[++cntE] = {v,Head[u]};Head[u] = cntE;
}
vector <pii> c2[N + 5];
pii c1[M + 5][N + 5];
unordered_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(int i = head[u];i;i = e[i].nxt)
		if(!vis[e[i].v]&&e[i].v != fa)
			siz[u] += get_siz(e[i].v,u);
	return siz[u];
}
int get_root(int u,int fa,int Siz)
{
	int mx = Siz - siz[u],rt = -1;
	for(int i = head[u];i;i = e[i].nxt)
		if(!vis[e[i].v]&&e[i].v != fa)
			mx = max(mx,siz[e[i].v]),
			rt = max(rt,get_root(e[i].v,u,Siz));
	if(mx * 2 <= Siz)return u;
	return rt;
}
void init1(int st,int *dis,pii *c)
{
	Q.push(st);dis[st] = 0;int cnt = 0;
	while(!Q.empty())
	{
		int u = Q.front();Q.pop();
		c[cnt++] = {dis[u],u};
		for(int i = Head[u];i;i = E[i].nxt)
			if(E[i].v != st&&!dis[E[i].v]&&!vis[E[i].v])
				dis[E[i].v] = dis[u] + 1,Q.push(E[i].v);
	}
}
void init2(int st,int *dis,vector <pii> &c)
{
	Q.push(st);dis[st] = 0;
	while(!Q.empty())
	{
		int u = Q.front();Q.pop();
		c.push_back({dis[u],u});
		mp[st][u] = dis[u];
		for(int i = head[u];i;i = e[i].nxt)
			if(e[i].v != st&&!dis[e[i].v]&&!vis[e[i].v])
				dis[e[i].v] = dis[u] + 1,Q.push(e[i].v);
	}
	for(auto now : c)dis[now.second] = 0;
}
int solve(int u)
{
	vis[u] = 1;init2(u,Dis,c2[u]);
	for(int i = head[u];i;i = e[i].nxt)
		if(!vis[e[i].v])
			f[solve(get_root(e[i].v,u,get_siz(e[i].v,u)))] = u;
	return u;
}
void dij(ll x)
{
	for(int i = 1;i <= n;i++)
		C[i] = c[i] + w[i] * x,d[i] = vis[i] = t1[i] = t2[i] = 0;
	q.push({0,1});vis[1] = 1;
	while(!q.empty())
	{
		int u = q.top().second;q.pop();
		for(int i = 1;i <= cnt;i++)
		{
			int noww = b[u] - dis[i][u];
			while(t1[i] < n)
			{
				int v = c1[i][t1[i]].second;
				if(c1[i][t1[i]].first > noww)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)
		{
			int noww = b[u] - mp[now][u];
			while(t2[now] != c2[now].size())
			{
				int v = c2[now][t2[now]].second;
				if(c2[now][t2[now]].first > noww)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()
{
	IO.init();
	n = read();m = read();T = read();
	dsu.init(n);
	for(int i = 1;i <= n;i++)
		b[i] = read(),c[i] = read(),w[i] = read();
	for(int i = 1;i <= m;i++)
	{
		u = read(),v = read();
		addE(u,v);addE(v,u);
		if(dsu.merge(u,v))adde(u,v),adde(v,u);
		else a[++cnt] = u;
	}
	for(int i = 1;i <= cnt;i++)init1(a[i],dis[i],c1[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++)print(ans[i],'\n');
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 41988kb

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: 0ms
memory: 137036kb

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
1061109567
1061109567
1061109567
1061109567
1061109567
1061109567
1061109567
1061109567
1061109567
1061109567
1061109567
1061109567
1061109567
1061109567
1061109567
1061109567
1061109567
1061109567
1061109567
1061109567
1061109567
1061109567
1061109567
1061109567
1061109567
1061109567
1061109567
1...

result:

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