QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#250109#4686. ToursClHg2WA 0ms3868kbC++141.7kb2023-11-12 21:27:482023-11-12 21:27:48

Judging History

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

  • [2023-11-12 21:27:48]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3868kb
  • [2023-11-12 21:27:48]
  • 提交

answer

#include <bits/stdc++.h>
#define EVAL(x) #x " = " << (x)

using std::cin;
using std::cout;
using i64 = std::int64_t;
using u32 = std::uint32_t;
using u64 = std::uint64_t;

namespace Random {
    const u32 seed = std::chrono::steady_clock().now().time_since_epoch().count();
    std::mt19937_64 rng{seed};
} // namespace Random

i64 gcd(i64 a, i64 b)
{
    return b == 0 ? a : gcd(b, a % b);
}

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

    int n{}, m{};
    cin >> n >> m;

    std::vector<std::vector<std::tuple<int, int, int>>> links(n);
    for (int i{}; i < m; ++i) {
        int u{}, v{}, w{1};
        cin >> u >> v, --u, --v;
        links[u].emplace_back(v, w, i), links[v].emplace_back(u, w, i);
    }

    int tot{};
    i64 ans{};
    std::vector<i64> dis(n);
    std::vector<u64> val(n);
    std::vector<bool> vis(n);
    std::map<u64, i64> sum;

    auto dfs{[&](auto dfs, int u, int w, int from) -> void {
        vis[u] = true;
        for (auto [v, w, id] : links[u]) {
            if (id == from)
                continue;
            if (!vis[v])
                dis[v] = dis[u] + w, dfs(dfs, v, w, id), val[u] ^= val[v];
            else if (dis[v] < dis[u]) {
                u64 x{Random::rng()};
                sum[x] += w, val[u] ^= x, val[v] ^= x;
                ans = gcd(ans, dis[u] - dis[v] + w);
            }
        }
        if (~from)
            sum[val[u]] += w;
    }};

    for (int i{}; i < n; ++i)
        if (!vis[i])
            dfs(dfs, i, 0, -1);

    for (auto [v, c] : sum)
        if (v)
            ans = gcd(ans, c * 2);

    for (i64 i{1}; i <= ans; ++i)
        if (ans % i == 0)
            cout << i << " ";
    cout << "\n";
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3696kb

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: 3620kb

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: 3656kb

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: -100
Wrong Answer
time: 0ms
memory: 3868kb

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 4 

result:

wrong answer Output contains longer sequence [length = 3], but answer contains 2 elements