QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#379741#8029. Traveling Merchantcomeintocalm#WA 52ms3772kbC++171007b2024-04-06 18:43:372024-04-06 18:43:37

Judging History

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

  • [2024-08-07 20:25:21]
  • hack成功,自动添加数据
  • (/hack/771)
  • [2024-04-06 18:43:37]
  • 评测
  • 测评结果:WA
  • 用时:52ms
  • 内存:3772kb
  • [2024-04-06 18:43:37]
  • 提交

answer

#include <bits/stdc++.h>

int main() {
    // freopen("in", "r", stdin);
    int ttt;
    std::cin >> ttt;
    while (ttt--) {
        int n, m;
        std::cin >> n >> m;
        std::string cl;
        std::cin >> cl;
        std::vector<std::vector<int>> ver(n);
        for (int i = 0; i < m; ++i) {
            int u, v;
            std::cin >> u >> v;
            ver[u].emplace_back(v);
            ver[v].emplace_back(u);
        }

        bool ans = false;
        std::vector<bool> vis(n), used(n);
        auto dfs = [&] (auto dfs, const int u) -> void {
            vis[u] = true;
            used[u] = true;
            for (auto &v: ver[u]) {
                if (cl[u] == cl[v] && vis[v]) {
                    ans = true;
                }
                if (cl[u] != cl[v] && !used[v]) {
                    dfs(dfs, v);
                }
            }
            vis[u] = false;
        };

        dfs(dfs, 0);

        std::cout << (ans ? "yes" : "no") << '\n';
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3772kb

input:

2
4 4
LHLH
0 1
1 2
1 3
2 3
3 3
LHH
0 1
0 2
1 2

output:

yes
no

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 52ms
memory: 3752kb

input:

12385
9 29
LHLLHLHLH
0 7
1 4
4 6
2 0
4 2
6 5
8 4
7 1
2 6
7 3
7 2
8 7
1 3
5 3
0 8
4 0
0 5
8 1
8 6
3 2
0 1
1 2
6 3
2 5
6 0
3 0
5 4
4 3
7 5
7 15
LLLLLHL
5 2
6 3
3 0
0 6
4 5
1 4
6 1
0 5
3 4
5 6
1 0
2 6
0 2
4 2
0 4
6 6
LHHHHH
5 0
0 4
2 5
1 4
1 3
3 4
9 8
LHLHLLHLL
5 7
5 4
7 4
7 8
1 5
0 1
1 8
1 2
5 4
LHHHH...

output:

yes
yes
no
no
no
yes
yes
yes
no
yes
yes
no
yes
yes
yes
yes
yes
yes
yes
yes
no
no
no
yes
no
no
yes
yes
no
no
yes
no
no
yes
yes
yes
yes
yes
yes
no
no
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
no
yes
yes
yes
yes
yes
yes
no
yes
yes
no
yes
yes
yes
yes
yes
yes
no
no
no
yes
yes
yes
no
yes
yes...

result:

wrong answer 568th lines differ - expected: 'yes', found: 'no'