QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#622834#5307. Subgraph IsomorphismduduFreireCompile Error//C++173.3kb2024-10-09 06:39:562024-10-09 06:39:56

Judging History

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

  • [2024-10-09 06:39:56]
  • 评测
  • [2024-10-09 06:39:56]
  • 提交

answer

#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2")
#include <bits/stdc++.h>

#define ll long long
#define endl '\n'
#define pb push_back
#define eb emplace_back
#define rep(i,a,b) for(int i=(int)(a); i < (int)(b);i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << x << endl
#define esp ' '
#define pii pair<int,int>
#define vi vector<int>
#define sz(x) ((int)(x).size())

using namespace std;

constexpr int oo = 0x3f3f3f3f3f3f3f3f;
constexpr int M = 23785125;
constexpr int mxI = 36;
constexpr ll MOD1 = 21412641264812894;
constexpr ll MOD2 = 17841234164112412;

struct DSU {
	vi p, rnk;
	DSU(int n) : p(n), rnk(n,0) {
		iota(all(p),0);
	}

	int find(int x) {
		return p[x] == x ? x : p[x]=find(p[x]);
	}

	bool merge(int a, int b) {
		a=find(a);
		b=find(b);
		if (a == b) return false;
		if (rnk[a] > rnk[b]) swap(a,b);

		rnk[b] += rnk[a]==rnk[b];
		p[a]=b;
		return true;
	}
};

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void solve() {
	int n,m;cin>>n>>m;
	vector<pair<int,int>> edges(m);

	rep(i,0,m) {
		int a,b;cin>>a>>b;a--;b--;
		edges[i]={a,b};
	}

	if (m == n-1) {
		cout << "YES\n";
		return;
	}


	auto hash=[&](auto self, vector<vi>& g, int a, int p=-1) -> ll{
		vector<ll> sons;	
		for (auto b : g[a]) if (b != p) {
			sons.pb(self(self, g, b, a));
		}
		sort(all(sons));

		ll po=418417123;
		ll ans=1958473849193;
		for (auto x : sons) {
			ans += po * x;
			if (ans >= 412412355) ans -= 36162378;
			//ans %= MOD1;
			po *= M;
			//po %= MOD1;
		}
		return ans;
	};

	auto test=[&](vector<vi>& g) {
		vi szs(n,0), ps(n);
		auto dfs1=[&](auto self, int a, int p) -> void{
			ps[a] = p;
			szs[a] = 1;
			for (auto b : g[a]) if (b != p) {
				self(self, b, a);
				szs[a] += szs[b];
			}
		};
		dfs1(dfs1, 0,-1);

		auto ctrd=[&](int a) {
			if (2*(n - szs[a]) > n) return false;			
			for (auto b : g[a]) if (b != ps[a]) {
				if (2*szs[b] > n) return false;
			}
			return true;
		};
		vi ctrds;
		rep(a,0,n) {
			if (ctrd(a)) ctrds.pb(a);	
		}

		vector<ll> ans;
		for (auto x : ctrds) ans.eb(hash(hash, g, x));
		return ans;
	};

	auto is_eq = [&](vector<ll> a, vector<ll> b) {
		if (sz(a) != sz(b)) return false;
		sort(all(a));
		sort(all(b));
		return a == b;
	};

	DSU dsu(n);
	auto dfstree=[&](vector<vi>& tree) {
		iota(all(dsu.p), 0);
		memset(&dsu.rnk[0], 0, n*sizeof(int));
		
		tree.assign(n, vi());
		shuffle(all(edges), rng);

		for (auto [a,b] : edges) {
			if (!dsu.merge(a,b)) continue;
			tree[a].pb(b);
			tree[b].pb(a);
		}
	};
	
	vector<vi> tree(n);
	dfstree(tree);

	auto hashs = test(tree);
	rep(_, 1, mxI) {
		dfstree(tree);
		auto hashc = test(tree);
		if (!is_eq(hashc, hashs)) {
			cout << "NO\n";
			return;
		}
	}
	cout << "YES\n";
}

signed main() {
	ios_base::sync_with_stdio(0);cin.tie(0);

	int t=1;
	cin>>t;
	while(t--) solve();
}


詳細信息

answer.code:26:20: warning: overflow in conversion from ‘long int’ to ‘int’ changes value from ‘4557430888798830399’ to ‘1061109567’ [-Woverflow]
   26 | constexpr int oo = 0x3f3f3f3f3f3f3f3f;
      |                    ^~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/string:43,
                 from /usr/include/c++/13/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:52,
                 from answer.code:10:
/usr/include/c++/13/bits/allocator.h: In destructor ‘std::_Vector_base<int, std::allocator<int> >::_Vector_impl::~_Vector_impl()’:
/usr/include/c++/13/bits/allocator.h:184:7: error: inlining failed in call to ‘always_inline’ ‘std::allocator< <template-parameter-1-1> >::~allocator() noexcept [with _Tp = int]’: target specific option mismatch
  184 |       ~allocator() _GLIBCXX_NOTHROW { }
      |       ^
In file included from /usr/include/c++/13/vector:66,
                 from /usr/include/c++/13/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:53:
/usr/include/c++/13/bits/stl_vector.h:133:14: note: called from here
  133 |       struct _Vector_impl
      |              ^~~~~~~~~~~~