QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#235666#7640. Colorful Cyclesucup-team870WA 144ms57312kbC++142.5kb2023-11-02 23:46:052023-11-02 23:46:06

Judging History

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

  • [2024-07-04 22:58:32]
  • hack成功,自动添加数据
  • (/hack/728)
  • [2023-11-02 23:46:06]
  • 评测
  • 测评结果:WA
  • 用时:144ms
  • 内存:57312kb
  • [2023-11-02 23:46:05]
  • 提交

answer

#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=l; i<=r; i++)
#define per(i,r,l) for(int i=r; i>=l; i--)
#define IOS {cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);}
using namespace std;

typedef long long ll;
typedef pair<int,int> P;

const int N = 2000010;
vector<P> e[N];
int vis[N], dfn[N], low[N], tim, sta[N], top, scc, bel[N], col[N][4], tmp[N], cnt[N];

void tarjan(int u, int father) {
    vis[u] = 1, dfn[u] = low[u] = ++tim, sta[++top] = u;
    for (auto [v, w]: e[u]) {
        if (v == father) continue;
        if (!dfn[v]) {
            tarjan(v, u);
            if (low[v] >= dfn[u]) {
                scc++;
                int now = -1;
                do {
                    now = sta[top--];
                    bel[now] = scc;
                } while (now != v);
            }
            low[u] = min(low[u], low[v]);
        }
        else if (vis[v]) low[u] = min(low[u], dfn[v]);
    }
}

int main() {
    int T; scanf("%d", &T);
    while (T--) {
        int n, m; scanf("%d%d", &n, &m);
        rep (i, 1, m) {
            int u, v, w;
            scanf("%d%d%d", &u, &v, &w);
            e[u].push_back(P(v, w));
            e[v].push_back(P(u, w));
        }
        rep (i, 1, n) if (!dfn[i]) {
            tarjan(i, 0);
        }
        top = 0;
        int flag = 0;
        rep (u, 1, n) {
            for (auto [v, w]: e[u]) {
                int ksj = dfn[u] > dfn[v]? bel[u]: bel[v];
                sta[++top] = ksj;
                col[ksj][w] = 1;
                if (tmp[ksj]) {
                    if (w != tmp[ksj]) tmp[ksj] = 4;
                } else {
                    tmp[ksj] = w;
                }
            }
            while (top) {
                int v = sta[top--];
                if (tmp[v] == 4) cnt[v]++;
                tmp[v] = 0;
                if (col[v][1] && col[v][2] && col[v][3] && cnt[v] >= 3) {
                    flag = 1;
                    break;
                }
            }
            if (flag) break;
        }
        // int flag = 0;
        // rep (i, 1, scc) {
        //     if (col[i][1] && col[i][2] && col[i][3] && cnt[i] >= 3) {
        //         flag = 1;
        //         break;
        //     }
        // }
        if (flag) puts("Yes");
        else puts("No");
        rep (i, 1, n) dfn[i] = low[i] = vis[i] = cnt[i] = col[i][2] = col[i][1] = col[i][3] = 0;
        scc = tim = top =0;
        rep (i, 1, n) e[i].clear();
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 7ms
memory: 56852kb

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: 144ms
memory: 57312kb

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 [12408th token]