QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#115879#5307. Subgraph IsomorphismPetroTarnavskyi#WA 41ms19088kbC++172.2kb2023-06-27 17:11:042023-10-15 17:26:03

Judging History

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

  • [2023-10-15 17:26:03]
  • 管理员手动重测本题所有提交记录
  • 测评结果:WA
  • 用时:41ms
  • 内存:19088kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-27 17:11:06]
  • 评测
  • 测评结果:0
  • 用时:37ms
  • 内存:18964kb
  • [2023-06-27 17:11:04]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define MP make_pair
#define PB push_back
#define F first
#define S second

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;

const int N = 400447;
const int mod[2] = {int(1e9) + 9, int(1e9) + 7};
const int p = 47;
VI g[N];
int pw[N][2];
int par[N];
bool used[N];
VI cycl;

int add(int a, int b, int md)
{
	a += b;
	if (a >= md)
		a -= md;
	return a;
}

int mult(int a, int b, int md)
{
	return LL(a) * b % md;
}

bool dfs1(int v, int from = -1)
{
	par[v] = from;
	used[v] = 1;
	bool ok = false;
	for (auto to : g[v])
	{
		if (to == from) continue;
		if (used[to])
		{
			cycl.PB(to);
			while (v != to)
			{
				cycl.PB(v);
				v = par[v];
			}			
			return true;
		}
		else
			ok |= dfs1(to, v);
		if (ok) return ok;
	}
	return false;
}
int sz[N];

PII dfs2(int v)
{
	sz[v] = 1;
	used[v] = 1;
	vector<PII> vec;
	for (auto to : g[v])
		if (!used[to]){
			vec.PB(dfs2(to));
			sz[v] += sz[to];
		}	
	sort(ALL(vec));
	PII hs = {(sz[v] + (sz[v] ^ 7)) , (sz[v] + (sz[v] ^ 7))};
	FOR (i, 0, SZ(vec)) hs = {	add(hs.first,  mult(pw[i + 1][0], vec[i].first,  mod[0]), mod[0]), 
								add(hs.second, mult(pw[i + 1][1], vec[i].second, mod[1]), mod[1])};
	return hs;
}

void solve()
{
	int n, m;
	cin >> n >> m;
	FOR (i, 0, m)
	{
		int a, b;
		cin >> a >> b;
		a--, b--;
		g[a].PB(b);
		g[b].PB(a);
	}
	if (m == n - 1)
	{
		cout << "YES\n";
	}
	else if (m > n)
	{
		cout << "NO\n";
	}
	else
	{
		dfs1(0, -1);
		FOR (i, 0, n) used[i] = 0;
		set<PII> s;
		for (auto v : cycl) used[v] = 1;
		for (auto v : cycl) s.insert(dfs2(v));
		cout << (SZ(s) < 2 ? "YES\n" : "NO\n"); 
	}
	cycl.clear();
	FOR (i, 0, n)
	{
		g[i].clear();
		used[i] = 0;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	pw[0][0] = pw[0][1] = 1;
	FOR (i, 1, N) FOR (j, 0, 2) pw[i][j] = mult(pw[i - 1][j], p, mod[j]); 
	
	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}
	
	return 0;
}


詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 18676kb

input:

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

output:

YES
YES
NO
YES

result:

ok 4 token(s): yes count is 3, no count is 1

Test #2:

score: -100
Wrong Answer
time: 41ms
memory: 19088kb

input:

33192
2 1
1 2
3 2
1 3
2 3
3 3
1 2
1 3
2 3
4 3
1 4
2 4
3 4
4 3
1 3
1 4
2 4
4 4
1 3
1 4
2 4
3 4
4 4
1 3
1 4
2 3
2 4
4 5
1 3
1 4
2 3
2 4
3 4
4 6
1 2
1 3
1 4
2 3
2 4
3 4
5 4
1 5
2 5
3 5
4 5
5 4
1 4
1 5
2 5
3 5
5 5
1 4
1 5
2 5
3 5
4 5
5 5
1 4
1 5
2 4
3 5
4 5
5 5
1 4
1 5
2 4
2 5
3 5
5 6
1 4
1 5
2 4
2 5
3 ...

output:

YES
YES
YES
YES
YES
NO
YES
NO
NO
YES
YES
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
YES
YES
NO
YES
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
...

result:

wrong answer expected YES, found NO [39th token]