QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#548742#4686. ToursPhantomThresholdWA 0ms3832kbC++202.1kb2024-09-05 20:33:182024-09-05 20:33:19

Judging History

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

  • [2024-09-05 20:33:19]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3832kb
  • [2024-09-05 20:33:18]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
vector<vector<int>> G;
int top;
void addedge(int u,int v)
{
	G[u].push_back(v);
	G[v].push_back(u);
}
namespace bf
{
	vector<vector<int>> G;
	void addedge(int u,int v)
	{
		G[u].push_back(v);
		G[v].push_back(u);
	}
	int ind;
	vector<int> dfn,low,ins;
	stack<int> s;
	void dfs(int u,int p)
	{
		dfn[u]=low[u]=++ind;
		s.push(u);ins[u]=1;
		for(auto v:G[u])
		{
			if(v==p)continue;
			if(not ins[v])
			{
				dfs(v,u);
				low[u]=min(low[u],low[v]);
				if(low[v]>=dfn[u])
				{
					++::top;
					int vv;
					do
					{
						vv=s.top();
						::addedge(::top,vv);
						ins[vv]=2;
						s.pop();
					}
					while(vv!=v);
					::addedge(::top,u);
				}
			}
			else if(ins[v]==1)
			{
				low[u]=min(low[u],low[v]);
			}
		}
		if(not p)s.pop();
	}
	void init(int n)
	{
		::G.clear();
		ins.clear();dfn.clear();low.clear();
		ind=0;
		::G.resize(n+n+5);
		::top=n;
		ins.resize(n+5);
		dfn.resize(n+5);
		low.resize(n+5);
		for(int i=1;i<=n;i++)
			if(not ins[i])
				dfs(i,0);
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	int n,m;
	cin>>n>>m;
	vector<pair<int,int>> edges;
	bf::G.resize(n+5);
	for(int i=1;i<=m;i++)
	{
		int u,v;
		cin>>u>>v;
		bf::addedge(u,v);
		edges.emplace_back(u,v);
	}
	bf::init(n);
	int ans=0;
	for(int c=n+1;c<=top;c++)
	{
		if(G[c].size()==2u)continue;
		vector<int> sp(n+5),deg(n+5);
		for(auto v:G[c])sp[v]=1;
		vector<vector<int>> G2(n+5);
		for(auto [u,v]:edges)
		{
			if(sp[u] and sp[v])
			{
				deg[u]++;deg[v]++;
				G2[u].push_back(v);
				G2[v].push_back(u);
			}
		}
		int g=0;
		function<void(int,int,int)> dfs2=[&](int u,int pa,int dis)
		{
			for(auto v:G2[u])
			{
				if(v==pa)continue;
				if(deg[v]>2)g=gcd(g,dis+1);
				else
				{
					dfs2(v,u,dis+1);
				}
			}
		};
		int cnt=0;
		for(auto v:G[c])
		{
			if(deg[v]>2)
			{
				dfs2(v,0,0);
				cnt++;
			}
		}
		if(cnt==0)ans=gcd(ans,(int)G[c].size());
		else ans=gcd(ans,g);
	}
	int fi=1;
	for(int i=1;i<=2000;i++)
	{
		if(ans%i==0)
		{
			if(not fi)cout<<' ';
			fi=0;
			cout<<i;
		}
	}
	return 0;
}

詳細信息

Test #1:

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

input:

4 5
1 2
2 3
3 4
1 4
1 3

output:

1

result:

ok 1 number(s): "1"

Test #2:

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

input:

6 6
1 2
2 3
1 3
1 4
2 5
3 6

output:

1 3

result:

ok 2 number(s): "1 3"

Test #3:

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

input:

4 5
1 2
3 4
2 3
1 4
1 3

output:

1

result:

ok 1 number(s): "1"

Test #4:

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

input:

6 6
1 2
2 3
1 4
2 5
1 3
3 6

output:

1 3

result:

ok 2 number(s): "1 3"

Test #5:

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

input:

9 10
1 2
2 3
3 4
4 5
5 6
6 7
7 8
1 8
4 9
6 9

output:

1 2

result:

ok 2 number(s): "1 2"

Test #6:

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

input:

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

output:

1

result:

ok 1 number(s): "1"

Test #7:

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

input:

33 36
2 22
12 18
27 28
9 19
26 27
6 21
15 16
2 3
7 24
3 12
4 23
28 29
5 14
29 30
1 10
11 13
6 13
16 25
14 21
4 16
10 19
10 11
5 15
1 8
3 20
7 13
25 26
29 31
17 23
8 18
12 24
25 30
31 32
17 20
15 22
9 18

output:

1

result:

wrong answer Answer contains longer sequence [length = 2], but output contains 1 elements