QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#463448#7640. Colorful CyclesCelestialCoderWA 115ms5884kbC++202.0kb2024-07-04 20:57:472024-07-04 20:57:48

Judging History

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

  • [2024-07-04 22:58:32]
  • hack成功,自动添加数据
  • (/hack/728)
  • [2024-07-04 20:57:48]
  • 评测
  • 测评结果:WA
  • 用时:115ms
  • 内存:5884kb
  • [2024-07-04 20:57:47]
  • 提交

answer

#include <bits/stdc++.h>
#ifdef SHARAELONG
#include "../../cpp-header/debug.hpp"
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

const int MAX_N = 5e5 + 1;

vector<pii> adj[MAX_N];
int bcc[MAX_N];
vector<int> st;
int low[MAX_N], dfn[MAX_N];
int piv = 0, c = 0;

void dfs(int x, int p){
    if (adj[x].empty()) {
        bcc[x] = ++c;
        return;
    }
    
    dfn[x] = low[x] = ++piv;
    st.push_back(x);
    for (auto[v, _]: adj[x]) {
        if (!dfn[v]) {
            dfs(v, x);
            low[x] = min(low[x], low[v]);
        } else if (v != p) {
            low[x] = min(low[x], dfn[v]);
        }
    }
    if (low[x] == dfn[x]) {
        c++;
        int e;
        do {
            e = st.back();
            st.pop_back();
            bcc[e] = c;
        } while (e != x);
    }
}

void solve() {
    int n, m;
    cin >> n >> m;
    st.clear();
    for (int i=0; i<=n; ++i) {
        adj[i].clear();
        bcc[i] = low[i] = dfn[i] = 0;
    }
    piv = 0; c = 0;

    for (int i=0; i<m; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        adj[a].push_back({ b, c });
        adj[b].push_back({ a, c });
    }
    
    dfs(1, -1);
    vector<pii> ok(c+1);
    for (int i=1; i<=n; ++i) {
        int b = bcc[i];
        for (auto[j, k]: adj[i]) ok[b].first |= (1 << k);
        bool monochrome = true;
        if (!adj[i].empty()) {
            for (int j=1; j<adj[i].size(); ++j) {
                if (adj[i][j].second != adj[i][0].second) {
                    monochrome = false;
                    break;
                }
            }
        }
        if (!monochrome) ok[b].second++;
    }
    for (int i=1; i<=c; ++i) {
        if (ok[i].first / 2 == 7 && ok[i].second >= 3) {
            cout << "Yes\n";
            return;
        }
    }
    cout << "No\n";
}

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

    int cases;
    cin >> cases;
    while (cases--) solve();
}

詳細信息

Test #1:

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

input:

2
3 3
1 2 3
2 3 1
1 3 2
5 6
1 2 1
2 3 1
1 3 2
3 4 3
3 5 3
4 5 3

output:

Yes
No

result:

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

Test #2:

score: -100
Wrong Answer
time: 115ms
memory: 5884kb

input:

100000
7 10
7 2 2
6 4 2
6 1 2
7 1 3
3 4 1
6 7 1
2 6 3
3 1 2
5 3 1
2 1 1
7 10
5 7 3
7 1 1
4 6 3
6 3 1
3 4 3
4 2 2
3 2 3
1 3 3
3 7 1
1 4 2
7 10
5 6 3
3 5 2
7 2 3
7 3 3
1 2 2
4 3 2
7 4 2
6 1 2
2 6 1
7 5 2
7 10
7 1 3
7 5 3
6 4 1
7 6 1
1 4 1
3 4 2
2 7 2
1 3 1
3 5 3
5 1 3
7 10
6 7 2
3 4 3
1 4 2
5 3 2
7 4 ...

output:

Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
...

result:

wrong answer expected NO, found YES [131st token]