QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#547037#6441. Ancient Magic Circle in TeyvatyhdddWA 0ms7960kbC++143.1kb2024-09-04 17:15:032024-09-04 17:15:05

Judging History

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

  • [2024-09-04 17:15:05]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:7960kb
  • [2024-09-04 17:15:03]
  • 提交

answer

// Problem: P9850 [ICPC2021 Nanjing R] Ancient Magic Circle in Teyvat
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P9850
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// Written by yhm.
// Start codeing:2024-09-04 16:28:27
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
#define int long long
#define mod 998244353ll
#define pii pair<int,int>
#define fi first
#define se second
#define mems(x,y) memset(x,y,sizeof(x))
#define pb push_back
using namespace std;
const int maxn=200010;
const int inf=1e18;
inline int read(){
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch-48);ch=getchar();}
	return x*f;
}
bool Mbe;

int n,m;
struct edge{
	int head[maxn],tot;
	struct nd{
		int nxt,to;
	}e[maxn<<1];
	void add(int u,int v){e[++tot]={head[u],v};head[u]=tot;}
}e,g;
int d[maxn];
/*
ans=|f0-f1+f2-f3+f4-f5|
f0=C(n,4)
f1=mC(n-2,2)
f2=(n-3)(\sum C(d[i],2))+C(m,2)-(\sum C(d[i],2))
f3=(n-3)c3+(\sum C(d[i],3))+(\sum (d[u]-1)(d[v]-1))-3c3
f4=(\sum cnt[i](d[i]-2))+c4
f5=(\sum C(num[u][v],2))
*/
int f0,f1,f2,f3,f4,f5,ans;
int vis[maxn],cnt[maxn],num[maxn],c3,c4;
void work(){
	n=read();m=read();
	for(int i=1;i<=m;i++){
		int u=read(),v=read();
		e.add(u,v),e.add(v,u);
		d[u]++,d[v]++;
	}
	for(int u=1;u<=n;u++){
		for(int i=e.head[u];i;i=e.e[i].nxt){
			int v=e.e[i].to;
			if(d[u]>d[v]||(d[u]==d[v]&&u>v))g.add(u,v);
		}
	}
	f0=n*(n-1)/2*(n-2)/3*(n-3)/4;
	f1=m*(n-2)*(n-3)/2;
	for(int i=1;i<=n;i++)f2+=(n-3)*d[i]*(d[i]-1)/2;
	f2+=m*(m-1)/2;
	for(int i=1;i<=n;i++)f2-=d[i]*(d[i]-1)/2;
	for(int u=1;u<=n;u++){
		for(int i=g.head[u];i;i=g.e[i].nxt){
			int v=g.e[i].to;
			vis[v]=i;
		}
		for(int i=g.head[u];i;i=g.e[i].nxt){
			int v=g.e[i].to;
			for(int j=g.head[v];j;j=g.e[j].nxt){
				int w=g.e[j].to;
				if(vis[w]){
					++c3;++cnt[u],++cnt[v],++cnt[w];
					num[i]++,++num[j],++num[vis[w]];
				}
			}
		}
		for(int i=g.head[u];i;i=g.e[i].nxt){
			int v=g.e[i].to;
			vis[v]=0;
		}
	}
	f3=(n-3)*c3;
	for(int i=1;i<=n;i++)f3+=d[i]*(d[i]-1)/2*(d[i]-2)/3;
	for(int u=1;u<=n;u++){
		for(int i=g.head[u];i;i=g.e[i].nxt){
			int v=e.e[i].to;
			f3+=(d[u]-1)*(d[v]-1);
		}
	}
	f3-=3*c3;
	for(int u=1;u<=n;u++){
		for(int i=g.head[u];i;i=g.e[i].nxt){
			int v=g.e[i].to;
			for(int j=e.head[v];j;j=e.e[j].nxt){
				int w=e.e[j].to;
				if(d[u]>d[w]||(d[u]==d[w]&&u>w))c4+=vis[w]++;
			}
		}
		for(int i=g.head[u];i;i=g.e[i].nxt){
			int v=g.e[i].to;
			for(int j=e.head[v];j;j=e.e[j].nxt){
				int w=e.e[j].to;
				vis[w]=0;
			}
		}
	}
	f4=c4;
	for(int i=1;i<=n;i++)f4+=cnt[i]*(d[i]-2);
	for(int i=1;i<=m;i++)f5+=num[i]*(num[i]-1)/2;
	// cout<<f0<<" "<<f1<<" "<<f2<<" "<<f3<<" "<<f4<<" "<<f5<<"\n";
	ans=abs(f0-f1+f2-f3+f4-f5);
	printf("%lld\n",ans);
}

// \
444

bool Med;
int T;
signed main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	
//	ios::sync_with_stdio(0);
//	cin.tie(0);cout.tie(0);
	
//	cerr<<(&Mbe-&Med)/1048576.0<<" MB\n";
	
	T=1;
	while(T--)work();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

7 6
1 2
1 3
1 4
2 3
2 4
3 4

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

4 0

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: 0
Accepted
time: 0ms
memory: 7960kb

input:

4 1
1 2

output:

0

result:

ok 1 number(s): "0"

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 7876kb

input:

4 2
1 2
1 3

output:

1

result:

wrong answer 1st numbers differ - expected: '0', found: '1'