QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#600884#9352. Highway BusesWrongAnswer_90TL 556ms224712kbC++237.9kb2024-09-29 19:48:122024-09-29 19:48:13

Judging History

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

  • [2024-09-29 19:48:13]
  • 评测
  • 测评结果:TL
  • 用时:556ms
  • 内存:224712kb
  • [2024-09-29 19:48:12]
  • 提交

answer

#include<bits/stdc++.h>
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define ll long long
#define lll __int128
#define fi first
#define se second
#define e emplace
#define eb emplace_back
#define db double
#define ef emplace_front
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vp vector<pii>
#define vt vector<tup>
#define all(x) x.begin(),x.end()
#define mp make_pair

#define FastI
#define FastO
#define int ll
bool ST;
static const ll MOD=1e8+7,Phi=998244352,inv2=499122177,Root=3,iRoot=332748118;
static const ll inf=1073741823,Inf=4294967296,INF=4557430888798830399;
static const ld eps=1e-9,pi=3.1415926535;
char in[1<<20],*p1=in,*p2=in;
char out[1<<20],*p3=out;
using namespace std;
struct tup
{
	int x,y,z;
	tup(int X=0,int Y=0,int Z=0)
	{x=X,y=Y,z=Z;}
};
#ifdef FastI
#define getchar() (p1==p2&&(p2=(p1=in)+fread(in,1,1<<20,stdin),p1==p2)?EOF:*p1++)
#endif
#ifdef FastO
#define putchar(x) (p3-out==1<<20?fwrite(out,1,1<<20,stdout),p3=out,0:0,*p3++=x)
#define puts(x) write(x,'\n')
#endif
namespace FastIO
{
	template<typename T> inline void write(T x,char ch=' ')
	{
		if(is_same<char,T>::value)putchar(x);
		else
		{
			if(x<0)x=-x,putchar('-');
			static char st[25];
			int top=0;
			do st[top++]=x%10+'0',x/=10;while(x);
			while(top)putchar(st[--top]);
		}
		ch!='~'?putchar(ch):0;
	}
	inline void write(const char*x,char ch=' ')
	{
		for(int i=0;x[i]!='\0';++i)putchar(x[i]);
		ch!='~'?putchar(ch):0;
	}
	inline void read(char&s){do s=getchar();while(s=='\n'||s==' ');}
	inline void read(char s[])
	{
		int len=0;char st;
		do st=getchar();while(st=='\n'||st==' ');
		s[++len]=st,st=getchar();
		while(st!='\n'&&st!=' ')s[++len]=st,st=getchar();
		s[++len]='\0';
	}
	template<typename T> inline void read(T &s)
	{
		char ch=getchar();s=0;
		while((ch>'9'||ch<'0')&&ch!='-')ch=getchar();
		bool tf=(ch=='-'&&(ch=getchar()));
		while(ch>='0'&&ch<='9')s=(s<<1)+(s<<3)+ch-'0',ch=getchar();
		s=tf?-s:s;
	}
	inline void edl(){putchar('\n');}
	template<typename T1,typename T2> inline void read(pair<T1,T2> &s){read(s.fi),read(s.se);}
	template<typename T,typename...Args> inline void write(T x,Args...args){write(x,'~'),write(args...);}
	template<typename T,typename...Args> inline void read(T&x,Args&...args){read(x),read(args...);}
	#ifdef FastO
	struct Writer{~Writer(){fwrite(out,1,p3-out,stdout);}}Writ;
	#endif
}
using namespace FastIO;
namespace MTool
{
	inline int Cadd(int a,int b){return (ll)a+b>=MOD?(ll)a+b-MOD:a+b;}
	inline int Cdel(int a,int b){return a-b<0?a-b+MOD:a-b;}
	inline int Cmul(int a,int b){return 1ll*a*b%MOD;}
	inline int sqr(int a){return 1ll*a*a%MOD;}
	inline void Madd(int&a,int b){a=((ll)a+b>=MOD?(ll)a+b-MOD:a+b);}
	inline void Mdel(int&a,int b){a=(a-b<0?a-b+MOD:a-b);}
	inline void Mmul(int&a,int b){a=1ll*a*b%MOD;}
	inline int Cmod(int x){return (x%MOD+MOD)%MOD;}
	inline void Mmod(int&x){x=(x%MOD+MOD)%MOD;}
	template<typename T> inline bool Mmax(T&a,T b){return a<b?a=b,1:0;}
	template<typename T> inline bool Mmin(T&a,T b){return a>b?a=b,1:0;}
	template<typename...Args> inline void Madd(int&a,int b,Args...args){Madd(a,b),Madd(a,args...);}
	template<typename...Args> inline void Mmul(int&a,int b,Args...args){Mmul(a,b),Mmul(a,args...);}
	template<typename...Args> inline void Mdel(int&a,int b,Args...args){Mdel(a,b),Mdel(a,args...);}
	template<typename...Args> inline int Cadd(int a,int b,Args...args){return Cadd(Cadd(a,b),args...);}
	template<typename...Args> inline int Cmul(int a,int b,Args...args){return Cmul(Cmul(a,b),args...);}
	template<typename...Args> inline int Cdel(int a,int b,Args...args){return Cdel(Cdel(a,b),args...);}
	template<typename...Args,typename T> inline bool Mmax(T&a,T b,Args...args){return Mmax(a,b)|Mmax(a,args...);}
	template<typename...Args,typename T> inline bool Mmin(T&a,T b,Args...args){return Mmin(a,b)|Mmin(a,args...);}
	inline int power(int x,int y){int s=1;for(;y;y>>=1,Mmul(x,x))if(y&1)Mmul(s,x);return s;}
}
using namespace MTool;
namespace WrongAnswer_90
{
	int n,m,TT,f[200010],c[200010],w[200010];
	int dep[21][200010],rdep[200010];
	int d[110][200010];
	int ans[200010];
	int all,rt,minn,siz[200010];
	int fa[200010];
	int up[200010];
	bool vis[200010],ins[200010];
	int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);}
	vi T[200010],G[200010],ve,qu[200010],qu2[110];
	priority_queue<pii> Q;
	void findrt(int x,int fa)
	{
		int maxn=0;
		ins[x]=0,siz[x]=1;
		for(auto to:T[x])if(to!=fa&&!vis[to])
		findrt(to,x),Mmax(maxn,siz[to]),siz[x]+=siz[to];
		if(Mmin(minn,max(maxn,all-siz[x])))rt=x;
	}
	int starch(int x,int dp=1)
	{
		minn=inf,findrt(x,0),x=rt,findrt(rt,0);
		rdep[x]=dp,vis[x]=1;
		cerr<<x<<" "<<dp<<endl;
		queue<int> q;q.e(x);
		while(!q.empty())
		{
			int nw=q.front();q.pop();
			ins[nw]=1;
			qu[x].eb(nw);
			for(auto to:T[nw])if(!ins[to]&&!vis[to])
			q.e(to),dep[dp][to]=dep[dp][nw]+1;
		}
		reverse(qu[x].begin(),qu[x].end());
		for(auto to:T[x])if(!vis[to])all=siz[to],up[starch(to,dp+1)]=x;
		return x;
	}
	inline pii get()
	{
		while(1)
		{
			int nw=Q.top().se,tmp=nw;
//			cerr<<nw<<endl;
//			exit(0);
			while(tmp)
			{
				while(qu[tmp].size()&&vis[qu[tmp].back()])qu[tmp].pop_back();
//				cerr<<tmp<<" "<<(qu[tmp].size()?qu[tmp].back():-1)<<endl;
//				if(qu[tmp].size())cerr<<"???"<<rdep[tmp]<<" "<<dep[rdep[tmp]][qu[tmp].back()]<<" "<<
//				dep[rdep[tmp]][nw]<<" "<<f[nw]<<endl;
				if(qu[tmp].size()&&dep[rdep[tmp]][qu[tmp].back()]
				+dep[rdep[tmp]][nw]<=f[nw])
				return cerr<<Q.top().se<<":",mp(qu[tmp].back(),-Q.top().fi);
				tmp=up[tmp];
			}
			for(int i=0;i<(int)ve.size();++i)
			{
				while(qu2[i].size()&&vis[qu2[i].back()])qu2[i].pop_back();
				if(qu2[i].size()&&d[i][qu2[i].back()]+d[i][nw]<=f[nw])
				return cerr<<Q.top().se<<":", mp(qu2[i].back(),-Q.top().fi);
			}
			Q.pop();
		}
	}
	void solve()
	{
		for(int i=1;i<=n;++i)qu[i].clear();
		memset(d,127,sizeof(d));
		for(int i=0;i<(int)ve.size();++i)
		{
			qu2[i].clear();
			queue<int> q;
			d[i][ve[i]]=0,q.e(ve[i]);
			while(!q.empty())
			{
				int nw=q.front();q.pop();
				qu2[i].eb(nw);
				for(auto to:G[nw])
				{
					if(Mmin(d[i][to],d[i][nw]+1))
					q.e(to);
				}
			}
			reverse(qu2[i].begin(),qu2[i].end());
//			write(ve[i],'\n');
//			for(auto p:qu2[i])write(p);puts("");
//			for(int j=1;j<=n;++j)write(d[i][j]);puts("");
//			puts("");
		}
//		exit(0);
		memset(vis,0,sizeof(vis));
		all=n,starch(1);
//		for(int i=1;i<=n;++i)write(rdep[i]);puts("");
//		for(int i=1;i<=20;++i,puts(""))
//		for(int j=1;j<=n;++j)write(dep[i][j]);
//		exit(0);
//		for(int i=1;i<=n;++i)write(up[i]);puts("");
//		for(int i=1;i<=n;++i)
//		{
//			write(i,'\n');
//			for(auto p:qu[i])write(p);puts("");
//		}
//		exit(0);
		while(!Q.empty())Q.pop();
		Q.e(mp(-c[1],1));
		memset(vis,0,sizeof(vis)),vis[1]=1;
		for(int i=2;i<=n;++i)
		{
			pii nw=get();
			cerr<<i<<" "<<nw.fi<<" "<<nw.se<<endl;
			vis[nw.fi]=1;
			Mmin(ans[nw.fi],nw.se);
			Q.e(mp(-nw.se-c[nw.fi],nw.fi));
		}
	}
	inline void mian()
	{
		read(n,m,TT);int x,y;
		for(int i=1;i<=n;++i)read(f[i],c[i],w[i]),fa[i]=i;
		for(int i=1;i<=m;++i)
		{
			read(x,y);
			G[x].eb(y),G[y].eb(x);
			if(find(x)==find(y)){ve.eb(x),ve.eb(y);continue;}
			T[x].eb(y),T[y].eb(x);
			fa[find(x)]=find(y);
		}
		sort(ve.begin(),ve.end());
		ve.resize(unique(ve.begin(),ve.end())-ve.begin());
		memset(ans,127,sizeof(ans));
		solve();
		for(int i=1;i<=n;++i)c[i]=c[i]+w[i]*(TT-1);
//		for(int i=1;i<=n;++i)cerr<<c[i]<<" ";
//		exit(0);
		solve();
		ans[1]=0;
		for(int i=1;i<=n;++i)write(ans[i],'\n');
	}
	inline void Mian()
	{
		int T=1;
//		read(T);
		while(T--)mian();
	}
}
bool ED;
signed main()
{
//	freopen("1.in","r",stdin);
//	freopen("1.out","w",stdout);
	double st=clock();
	WrongAnswer_90::Mian();
	double ed=clock();
 	cerr<<endl;
 	cerr<<"Time: "<<ed-st<<" ms\n";
 	cerr<<"Memory: "<<abs(&ST-&ED)/1024.0/1024.0<<" MB\n";
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 16ms
memory: 188364kb

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: 0
Accepted
time: 30ms
memory: 187472kb

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
1277292628
1239671692
1255261807
1284074004
1270230633
1239671692
1284074004
1271369537
1277292628
1205507860
1270615693
1300179417
1205507860
1205507860
1239671692
1251564675
1239671692
1284004371
1239671692
1239671692
1277292628
1270230633
1284004371
1277292628
1255261807
1276194392
1247939403
1...

result:

ok 500 lines

Test #3:

score: 0
Accepted
time: 36ms
memory: 188968kb

input:

500 540 1000000
1 613142394 -268
5 920609625 740
2 755612530 -255
2 23678897 -4
5 325892468 291
5 707223319 -140
1 679600699 -138
5 625157055 690
2 141819870 995
1 250348582 -219
2 581461324 -580
4 339782234 -82
5 810851082 230
3 378119535 158
4 295102386 677
5 854435300 21
3 565535907 -465
2 820995...

output:

0
2421015760
2617367920
2694215005
2812156460
2412108889
2370843291
2786283443
2412108889
2197157944
2412108889
2633707306
2370843291
2478757415
2672183755
2478757415
2633707306
2812156460
1984181483
2464420418
2548091380
2421015760
2421015760
2412108889
2421015760
2421015760
2412108889
2412108889
2...

result:

ok 500 lines

Test #4:

score: 0
Accepted
time: 31ms
memory: 188008kb

input:

500 544 1000000
2 587500219 -573
3 800375803 -606
2 332196789 -11
2 782258272 270
2 690828422 -145
2 642751384 -107
4 78645508 -68
3 692764955 364
5 739361677 -104
4 139030619 -125
5 698401632 -121
3 654935300 401
4 70734757 -57
2 763502749 911
1 71485824 836
1 292976518 -290
1 743618801 659
2 64895...

output:

0
425794735
442014967
675968705
311908134
675968705
336563578
425794735
523701048
479984544
425794735
425794735
425794735
708001283
311908134
1653971237
425794735
580659172
425794735
487630114
311908134
450399440
1653971237
425957613
425794735
425957613
336604992
336604992
425794735
436034689
425794...

result:

ok 500 lines

Test #5:

score: 0
Accepted
time: 27ms
memory: 188084kb

input:

500 543 1000000
4 753661240 -312
2 281450837 -151
9 28464686 987
7 685967710 490
8 592650944 542
10 141100249 83
10 646501804 -94
3 337312645 294
2 904175548 -870
8 281667853 -136
3 36477141 -26
5 476645115 -195
1 21897824 -7
10 517151723 150
1 291410319 941
7 993616997 143
10 628559241 -428
8 10757...

output:

0
445387723
445387723
450719457
455897864
445387723
449974501
449974501
449974501
444157947
449974501
449974501
449974501
449974501
449974501
445387723
441661552
449974501
449974501
449974501
444157947
444157947
444157947
449974501
444157947
444157947
449974501
445387723
441661552
449974501
45156161...

result:

ok 500 lines

Test #6:

score: 0
Accepted
time: 36ms
memory: 186776kb

input:

500 547 1000000
7 579418 0
1 769742 0
1 133755 0
2 996071 0
2 96075 893
7 484503 0
7 645976 141
6 80570 0
2 33751 124
4 218617 701
5 686104 0
1 675119 586
3 294461 0
5 319865 0
9 178301 179
1 547068 0
1 96921 802
3 725739 58
8 646648 0
4 667865 0
6 816462 0
4 901406 37
4 834211 0
1 364051 263
2 1014...

output:

0
653962
626600
579418
626600
603269
603269
626600
626600
634782
626600
672297
579418
626600
626600
579418
626600
579418
626600
672297
626600
661975
672297
746441
626600
661975
626600
626600
626600
626600
579418
626600
653962
661975
626600
626600
579418
579418
626600
579418
579418
626600
634782
6266...

result:

ok 500 lines

Test #7:

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

input:

500 549 1000000
8 275979 799
2 323404 0
8 286448 610
2 877230 292
5 111405 972
2 686865 757
6 542128 0
9 823472 705
8 551203 0
9 900802 0
8 497319 554
2 60284 473
1 128784 147
1 390099 282
1 376548 407
7 444338 502
10 496911 293
7 133528 0
1 949531 669
8 569605 459
1 310534 504
2 705803 0
5 954861 0...

output:

0
308634
296602
275979
275979
275979
308634
296754
296602
275979
296602
308634
275979
275979
275979
296602
275979
296602
275979
296602
308634
296602
275979
300889
275979
275979
275979
275979
296754
296602
324141
275979
296754
296754
308634
296602
308634
308634
275979
296754
275979
275979
324141
2759...

result:

ok 500 lines

Test #8:

score: 0
Accepted
time: 556ms
memory: 221492kb

input:

30000 30047 786577
2 418118 886
1 923620 -1
1 396304 59
1 357673 0
1 12272 51
2 797480 0
2 41479 797
1 970539 -1
1 608143 0
2 415150 0
1 459616 0
1 739232 742
1 917012 -1
1 165211 0
1 637917 550
1 238131 0
2 232835 258
2 610877 0
1 17235 0
2 112947 446
2 828314 0
2 179873 782
2 333590 0
1 961918 194...

output:

0
80494179
83741087
62038907
76473105
104910654
116145079
108446496
88716481
94285072
115284209
99860695
77584533
119165550
81758989
77570762
142596283
79902868
77267149
95599129
114945135
73806480
108069554
77051483
76742645
57016312
152581721
89223155
76282889
122548472
23429774
107080496
76205230...

result:

ok 30000 lines

Test #9:

score: 0
Accepted
time: 465ms
memory: 224712kb

input:

30000 30050 605850
9 564340 974
2 843284 -1
1 398311 922
9 478997 556
7 671058 -1
3 671222 872
2 943222 -1
3 357119 393
8 108556 258
2 579805 0
5 452884 0
7 578644 871
4 863186 157
8 47757 0
10 635134 678
4 73374 1000
4 614076 0
3 549192 0
8 945587 0
5 67239 48
5 943401 992
9 345170 459
6 164234 0
5...

output:

0
9452611
15305660
6254895
8166386
10065348
6017741
6884440
17917177
6017741
7241812
5274395
6017741
6017741
10160098
6017741
8872246
7061933
10080339
8597089
5885039
6017741
6017741
12747501
7589567
13233135
6017741
12499965
6017741
8353713
11425708
6017741
6017741
6017741
7468089
8335888
9588729
6...

result:

ok 30000 lines

Test #10:

score: -100
Time Limit Exceeded

input:

200000 200047 812175
1 850300 0
1 913813 609
1 148997 755
1 5275 0
1 989899 -1
1 843074 -1
1 131757 0
1 713341 0
1 530046 919
1 243794 0
1 127575 558
1 385431 694
1 94653 0
1 556880 189
1 718137 564
1 968120 -1
1 358633 973
1 2321 0
1 331378 0
1 164889 583
1 70541 710
1 338259 54
1 866090 73
1 31800...

output:


result: