QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#94999#6127. Kawa Examysghwzp#WA 2ms10460kbC++142.5kb2023-04-08 16:52:512023-04-08 16:52:55

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-08 16:52:55]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:10460kb
  • [2023-04-08 16:52:51]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=100005,mod=1e9+7;
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define pb push_back
int n,m,ncnt,s[N],t[N],sz[N],son[N],a[N],bel[N],fa[N],ans1[N],ans2[N],ans[N];
int dfn[N],low[N],ti;
vector<int> cur,ve[N],v[N],V[N];
void tarjan(int p,int fa){
	dfn[p]=low[p]=++ti;
	for(auto i:v[p])if(i==fa){
		fa=0;
	}else if(!dfn[i]){
		tarjan(i,p);
		low[p]=min(low[p],low[i]);
	}else{
		low[p]=min(low[p],dfn[i]);
	}
	cur.pb(p);
	if(low[p]==dfn[p]){
		ncnt++;
		for(auto i:cur)bel[i]=ncnt;
		ve[ncnt]=cur;
		cur.clear();
	}
}
int to1[N],to2[N],mx;
int get(){
	return mx;
}
void add(int p,int de){
	for(auto i:ve[p]){
		int &x=to1[a[i]];
		to2[x]--;
		if(!to2[x])mx--;
		x+=de;
		to2[x]++;
		if(x>mx)mx=x;
	}
}
void dfsadd(int p,int de){
	add(p,de);
	for(auto i:V[p])if(i!=fa[p])dfsadd(i,de);
}
void dsu1(int p,int de){
	//cerr<<p<<" "<<de<<endl;
	for(auto i:V[p])if(i!=fa[p]&&i!=son[p]){
		dsu1(i,0);
	}
	if(son[p])dsu1(son[p],1);
	add(p,1);
	for(auto i:V[p])if(i!=fa[p]&&i!=son[p]){
		dfsadd(i,1);
	}
	ans1[p]=get();
	if(de==0)dfsadd(p,-1);
}
void dsu2(int p,int de){
	ans2[p]=get();
	add(p,1);
	for(auto i:V[p])if(i!=fa[p]&&i!=son[p]){
		dfsadd(i,1);
	}
	if(son[p])dsu2(son[p],1);
	for(auto i:V[p])if(i!=fa[p]&&i!=son[p]){
		dfsadd(i,-1);
		dsu2(i,1);
	}
	if(de==0)dfsadd(p,-1);
}
void dfs(int p){
	sz[p]=ve[p].size();
	cur.pb(p);
	for(auto i:V[p])if(i!=fa[p]){
		fa[i]=p;
		dfs(i);
		sz[p]+=sz[i];
		if(son[p]==0||sz[i]>sz[son[p]])son[p]=i;
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int T;
	cin>>T;
	while(T--){
		cin>>n>>m;
		For(i,1,n)cin>>a[i];
		ncnt=ti=0;
		For(i,1,n){
			v[i].clear(); ve[i].clear(); fa[i]=son[i]=sz[i]=0;
		}
		For(i,1,m){
			cin>>s[i]>>t[i];
			v[s[i]].pb(t[i]);
			v[t[i]].pb(s[i]);
		}
		For(i,1,n)if(!dfn[i])tarjan(i,0);
		For(i,1,n)for(auto j:v[i])if(bel[i]!=bel[j])V[bel[i]].pb(bel[j]);
		int sum=0;
		For(i,1,ncnt)if(!sz[i]){
			cur.clear();
			dfs(i);
			dsu1(i,0);
			dsu2(i,0);
			sum+=ans1[i];
			for(auto x:cur)ans[x]=ans1[x]+ans2[x]-ans1[i];
		}
		For(i,1,ncnt)ans[i]+=sum;
		For(i,1,m){
			if(fa[bel[s[i]]]==bel[t[i]]){
				cout<<ans[bel[s[i]]];
			}else if(fa[bel[t[i]]]==bel[s[i]]){
				cout<<ans[bel[t[i]]];
			}else cout<<sum;
			cout<<(i<m?" ":"\n");
		}
	}
}
/*
1
7 5
1 2 1 2 1 2 1
1 2
1 3
2 4
5 6
5 7

3
7 5
1 2 1 2 1 2 1
1 2
1 3
2 4
5 6
5 7
3 3
1 2 3
1 2
1 3
2 3
2 3
12345 54321
1 2
1 2
1 1

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 10460kb

input:

3
7 5
1 2 1 2 1 2 1
1 2
1 3
2 4
5 6
5 7
3 3
1 2 3
1 2
1 3
2 3
2 3
12345 54321
1 2
1 2
1 1

output:

6 5 5 5 4
6 0 0
6 6 0

result:

wrong answer 2nd lines differ - expected: '1 1 1', found: '6 0 0'