QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#308963#8136. Rebellious Edgeucup-team2303#WA 43ms58672kbC++142.7kb2024-01-20 14:02:032024-01-20 14:02:04

Judging History

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

  • [2024-01-20 14:02:04]
  • 评测
  • 测评结果:WA
  • 用时:43ms
  • 内存:58672kb
  • [2024-01-20 14:02:03]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
long long T,a,b,c,d[1000001],v[1000001],o,h[1000001],fa[1000001],q,w,e,an,cn,fac[1000001],inv[1000001],u[1000001],de[1000001],vv[1000001];
char s[1000001];
struct p{long long q,w,e;}l[1000001],st[1000001];
long long pow_(long long qq,long long ww){long long ee=1;while(ww){if(ww&1) ee*=qq,ee%=mod;qq*=qq,qq%=mod,ww>>=1;}return ee%mod;}
inline int read(){int x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}return x*f;}
void add(long long qq,long long ww){l[++o].q=ww,l[o].w=h[qq],h[qq]=o;}
long long gcd(long long qq,long long ww){return !ww?qq:gcd(ww,qq%ww);}
long long find(long long qq){return qq==fa[qq]?qq:fa[qq]=find(fa[qq]);}
void merge(long long qq,long long ww){long long f1=find(qq),f2=find(ww);if(f1==f2) return;fa[f1]=f2;}
long long C(long long qq,long long ww){return fac[qq]*inv[ww]%mod*inv[qq-ww]%mod;}
bool cmp(p qq,p ww){return qq.e<ww.e;}
vector<p> qu[1000001];
void dfs(long long qq)
{
	if(u[qq])
	{
		if(v[qq])
		{
			long long mn=0;
			for(int i=cn;i>=1;i--)
			{
				mn=max(mn,st[i].w);
				if(st[i].q==qq) break;
			}
			an-=mn;
		}
		return;
	}
	v[qq]=1;
	u[qq]=1;
	for(int i=0;i<qu[qq].size();i++)
	{
		st[++cn]=p{qq,qu[qq][i].w,0};
		dfs(qu[qq][i].q);
		--cn;
	}
	v[qq]=0;
}
int main()
{
//	freopen("1.in","r",stdin);
	srand((unsigned)(time(0)^(*new int)));
	fac[0]=1;for(int i=1;i<=1000000;i++) fac[i]=fac[i-1]*i%mod;
	inv[1000000]=pow_(fac[1000000],mod-2);for(int i=999999;i>=0;i--) inv[i]=inv[i+1]*(i+1)%mod;
	T=1;
	scanf("%lld",&T);
	for(int ii=1;ii<=T;ii++)
	{
		scanf("%lld%lld",&a,&b);
		o=0;
		for(int i=1;i<=a;i++) h[i]=de[i]=0,qu[i].clear(),u[i]=vv[i]=0;
		for(int i=1;i<=b;i++)
		{
			scanf("%lld%lld%lld",&q,&w,&e);
			l[i]=p{q,w,e};
			qu[q].push_back(p{w,e,0});
		}
		sort(l+1,l+b+1,cmp);
		an=0;
		long long gg=0,t1=0,t2=0,t3=0;
		for(int i=1;i<=b;i++)
		{
			if(l[i].q>l[i].w)
			{
				t1=l[i].q,t2=l[i].w,t3=l[i].e;
				continue;
			}
			if(de[l[i].w]==0)
			{
				de[l[i].w]++;
				fa[l[i].w]=l[i].q;
				u[l[i].w]=l[i].e;
				an+=l[i].e;
				++gg;
//				cout<<l[i].q<<" "<<l[i].w<<"\n";
			}
		}
		long long mx=0,ggg=t1;
		while(t1!=t2&&t1!=0) mx=max(mx,u[t1]),vv[t1]=1,t1=fa[t1];vv[t2]=1;
		if(t1==0)
		{
			if(u[t2]>t3) an-=u[t2],an+=t3;
		}
		else
		{
			long long an1=an+t3;
			an1-=u[t2];u[t2]=t3;
			for(int i=1;i<=a;i++)
			{
				if(vv[i]) continue;
				for(int j=0;j<qu[i].size();j++)
				{
					if(vv[qu[i][j].q])
					{
						an=min(an,an1-u[qu[i][j].q]+qu[i][j].w);
					}
				}
			}
		}
		printf("%lld\n",an);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 12ms
memory: 58608kb

input:

3
5 6
1 2 4
1 3 2
2 3 0
3 4 1
4 5 1
5 2 1
4 4
1 2 4
1 3 6
1 4 8
4 2 1000000
3 3
1 2 100
2 1 10
2 3 1000

output:

5
18
1100

result:

ok 3 number(s): "5 18 1100"

Test #2:

score: -100
Wrong Answer
time: 43ms
memory: 58672kb

input:

50000
4 5
2 4 998973548
2 3 501271695
4 1 778395982
1 4 32454891
1 2 757288934
4 5
1 4 720856669
2 3 665098951
3 4 407461517
2 1 866914401
1 2 457859826
4 5
1 2 75288664
1 4 624893594
3 2 458973866
2 4 769074655
2 3 834773751
4 5
2 3 237060634
2 4 297307882
3 4 200383586
1 2 42856502
3 1 16574713
4 ...

output:

1291015520
1530420294
1534956009
480300722
1366795927
1541095843
2493849488
858095911
1034153425
793861088
605832428
1051598350
612891589
1265994009
517769091
1678219738
1556463491
93634961
960978736
984886788
1696503797
1002892611
1969660290
1431417780
1515267731
977157479
1937478556
654475526
1401...

result:

wrong answer 301st numbers differ - expected: '1442045931', found: '1328599284'