QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#95004#6127. Kawa Examysghwzp#WA 614ms32064kbC++142.7kb2023-04-08 17:18:512023-04-08 17:18:54

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 17:18:54]
  • 评测
  • 测评结果:WA
  • 用时:614ms
  • 内存:32064kb
  • [2023-04-08 17:18: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;
	cur.pb(p);
	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]);
	}
	if(low[p]==dfn[p]){
		ncnt++;
		while(cur.back()!=p){
			ve[ncnt].pb(cur.back());
			bel[cur.back()]=ncnt;
			cur.pop_back();
		}
		ve[ncnt].pb(p);
		bel[p]=ncnt;
		cur.pop_back();
	}
	//cerr<<p<<" "<<dfn[p]<<" lyx "<<low[p]<<endl;
}
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;
		//cerr<<n<<" "<<m<<" lyx\n";
		For(i,1,n)cin>>a[i];
		ncnt=ti=0;
		cur.clear();
		For(i,1,n){
			v[i].clear(); ve[i].clear(); V[i].clear(); dfn[i]=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
3 3
1 2 3
1 2
1 3
2 3

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: 100
Accepted
time: 2ms
memory: 11440kb

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

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 614ms
memory: 32064kb

input:

5557
2 7
79960 79960
2 2
1 1
1 1
2 2
1 1
2 1
1 2
9 8
21881 70740 70740 21881 22458 22458 639 21881 70740
3 3
1 6
5 8
7 5
5 7
2 3
5 1
7 6
6 7
13064 20716 6746 13064 6746 69225
5 5
4 1
4 1
1 6
4 5
3 2
3 2
8 4
45146 14400 45146 45146 14400 72969 14400 45146
8 6
1 3
4 6
8 3
18 13
48132 37949 92338 92338...

output:

2 2 2 2 2 2 2
6 6 7 6 6 6 6 6
3 3 3 4 4 3 3
7 7 7 7
9 9 9 8 9 8 9 8 9 9 10 9 9
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
7 8
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
9 10 9
16 16 16 16 16 17 16 16
10 9 10 9 12 11 9 9 9 9 9 9 9 12 10 9 9 9 9 10
10 9 9 9 9 9 9 9 9 9 9 9 9 9 10 9 9 9
2 2 2 2...

result:

wrong answer 12th lines differ - expected: '10 10 11 10 12 11 10 10 10 10 10 10 10 12 10 10 10 10 10 11', found: '10 9 10 9 12 11 9 9 9 9 9 9 9 12 10 9 9 9 9 10'