QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#542575#7860. Graph of Maximum Degree 3RepeaterWA 0ms3600kbC++202.2kb2024-09-01 02:47:462024-09-01 02:47:46

Judging History

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

  • [2024-09-01 02:47:46]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3600kb
  • [2024-09-01 02:47:46]
  • 提交

answer

#include <bits/stdc++.h>

struct DSU 
{
    std::vector<int> f, siz;
    
    DSU() {}
    DSU(int n) 
    {
        init(n);
    }
    
    void init(int n) 
    {
        f.resize(n);
        std::iota(f.begin(), f.end(), 0);
        siz.assign(n, 1);
    }
    
    int find(int x) 
    {
        while (x != f[x]) 
        {
            x = f[x] = f[f[x]];
        }
        return x;
    }
    
    bool same(int x, int y) 
    {
        return find(x) == find(y);
    }
    
    bool merge(int x, int y) 
    {
        x = find(x);
        y = find(y);
        if (x == y) {
            return false;
        }
        siz[x] += siz[y];
        f[y] = x;
        return true;
    }
    
    int size(int x) 
    {
        return siz[find(x)];
    }
};

int main()
{
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);

	int n, m; std::cin >> n >> m;
	DSU dsu(n);

	std::vector<std::vector<int>> adj(n);
	std::vector<std::set<int>> adj2(n);
	for(int i = 0; i < m; i++)
	{
		int u, v, w; std::cin >> u >> v >> w;
		u--, v--;

		if(w == 0)
		{
			adj[u].emplace_back(v);
			adj[v].emplace_back(u);
		}
		else
		{
			if(u > v) std::swap(u, v);
			adj2[u].emplace(v);
		}
	}

	std::vector<int> tmp;

	auto check = [&]() -> int
	{
		int ok = 1;
		std::ranges::sort(tmp);
		for(int i = 0; i < tmp.size(); i++)
			for(int j = i + 1; j < tmp.size(); j++)
				if(adj2[tmp[i]].contains(tmp[j]))
					dsu.merge(tmp[i], tmp[j]);

		for(int i = 1; i < tmp.size(); i++)
			if(!dsu.same(tmp[0], tmp[i])) ok = 0;

		for(auto i : tmp) dsu.f[i] = i;

		// std::cerr << ok << " : ";
		// for(auto i : tmp) std::cerr << i + 1 << " ";
		// std::cerr << "\n";

		return ok;
	};	

	int ans = 0;
	std::vector<int> vis(n);
	auto cacl = [&](auto cacl, int x) -> void
	{
		ans += check();

		if(tmp.size() >= 4) return;
		for(auto y : adj[x])
		{
			if(vis[y]) continue;

			vis[y] = 1;
			tmp.emplace_back(y);
			cacl(cacl, y);

			if(tmp.size() == 4) tmp.pop_back(), vis[y] = 0;
		} 
	};

	for(int i = 0; i < n; i++) 
	{
		for(auto j : tmp) if(j >= i) vis[j] = 0;
		tmp.clear();
		tmp.emplace_back(i);
		vis[i] = 1;
		cacl(cacl, i);
	}

	std::cout << ans << "\n";

	return 0;
}

詳細信息

Test #1:

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

input:

3 4
1 2 0
1 3 1
2 3 0
2 3 1

output:

5

result:

ok 1 number(s): "5"

Test #2:

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

input:

4 6
1 2 0
2 3 0
3 4 0
1 4 1
2 4 1
1 3 1

output:

5

result:

ok 1 number(s): "5"

Test #3:

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

input:

20 28
9 6 1
9 6 0
3 8 0
8 4 0
3 8 1
3 4 1
2 13 0
13 1 0
19 1 0
2 1 1
2 19 1
13 19 1
14 15 1
14 15 0
7 12 0
12 17 0
20 17 0
7 17 1
7 20 1
12 20 1
16 18 0
18 10 0
5 10 0
16 10 1
16 5 1
18 5 1
4 6 0
9 11 0

output:

27

result:

ok 1 number(s): "27"

Test #4:

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

input:

100 150
93 23 0
23 81 0
76 81 0
93 81 1
93 76 1
23 76 1
100 65 0
65 56 0
19 56 0
100 56 1
100 19 1
65 19 1
2 98 0
2 98 1
26 63 0
63 90 0
26 63 1
26 90 1
6 11 0
11 67 0
6 11 1
6 67 1
37 89 0
89 64 0
25 64 0
37 64 1
37 25 1
89 25 1
84 10 0
10 29 0
75 29 0
84 29 1
84 75 1
10 75 1
7 70 1
7 70 0
28 92 0
...

output:

136

result:

wrong answer 1st numbers differ - expected: '141', found: '136'