QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#463557#7640. Colorful CyclesCelestialCoderRE 201ms47872kbC++202.2kb2024-07-05 00:24:542024-07-05 00:24:55

Judging History

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

  • [2024-07-05 00:24:55]
  • 评测
  • 测评结果:RE
  • 用时:201ms
  • 内存:47872kb
  • [2024-07-05 00:24:54]
  • 提交

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];
vector<int> bcc[MAX_N];
vector<int> st;
int low[MAX_N], dfn[MAX_N];
int piv = 0, c = 0;
pii edge[MAX_N];
int col[MAX_N];

void dfs(int x, int p){
    dfn[x] = low[x] = ++piv;
    for (auto[y, id]: adj[x]) {
        if (!dfn[y]) {
            st.push_back(id);
            dfs(y, x);
            low[x] = min(low[x], low[y]);
            if (low[y] >= dfn[x]) {
                ++c;
                while (!st.empty()) {
                    int tmp = st.back();
                    bcc[c].push_back(tmp);
                    st.pop_back();
                    if (tmp == id) break;
                }
            }
        } else if (y != p) {
            low[x] = min(low[x], dfn[y]);
            if (dfn[x] > dfn[y]) st.push_back(id);
        }
    }
}

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

    for (int i=0; i<m; ++i) {
        int a, b;
        cin >> a >> b >> col[i];
        adj[a].push_back({ b, i });
        adj[b].push_back({ a, i });
        edge[i] = {a, b};
    }
    
    dfs(1, -1);
    vector<int> ok(n+1, 0);
    for (int i=1; i<=c; ++i) {
        int edge_ok = 0;
        vector<int> ver;
        for (int id: bcc[i]) {
            auto[u, v] = edge[id];
            int j = col[id];
            edge_ok |= (1 << j);
            
            if (!ok[u]) ver.push_back(u);
            ok[u] |= (1 << j);
            if (!ok[v]) ver.push_back(v);
            ok[v] |= (1 << j);
        }
        
        int cnt = 0;
        for (int u: ver) cnt += (__builtin_popcount(ok[u]) >= 2);
        for (int u: ver) ok[u] = 0;
        if (edge_ok == 14 && cnt >= 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();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 0
Accepted
time: 127ms
memory: 10028kb

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:

ok 100000 token(s): yes count is 92314, no count is 7686

Test #3:

score: 0
Accepted
time: 101ms
memory: 9820kb

input:

50000
10 15
6 2 1
4 7 1
10 3 1
10 9 2
4 5 1
3 4 1
4 6 2
5 3 1
4 9 1
3 9 3
1 2 1
9 2 3
8 10 2
8 6 1
6 1 1
10 15
4 9 3
7 10 2
1 2 1
10 4 2
4 7 2
6 5 2
6 1 1
9 10 1
6 3 3
7 8 3
9 1 1
7 9 3
1 7 3
4 8 1
8 6 3
10 15
4 1 2
4 2 1
6 7 3
6 2 2
10 8 2
1 9 1
2 8 1
5 10 3
9 6 2
9 10 1
8 4 1
2 7 3
6 8 1
1 3 1
4 6...

output:

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
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
Yes
Yes
Yes
Yes
Ye...

result:

ok 50000 token(s): yes count is 49364, no count is 636

Test #4:

score: 0
Accepted
time: 117ms
memory: 7992kb

input:

50000
10 20
1 9 2
2 6 3
4 3 2
3 10 1
5 10 2
10 6 2
6 7 2
7 4 1
10 1 1
4 10 1
3 9 2
2 9 2
1 3 1
3 2 1
3 6 3
5 3 2
3 8 2
5 1 3
5 2 2
9 6 1
10 20
5 10 3
5 4 2
6 4 2
4 3 2
1 7 2
1 2 2
10 6 3
7 4 2
1 4 3
8 10 3
10 2 1
7 2 1
1 6 3
9 4 2
8 1 1
10 9 2
8 6 1
5 9 3
9 8 3
1 10 2
10 20
9 5 1
9 8 3
10 2 2
6 2 3
...

output:

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
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
...

result:

ok 50000 token(s): yes count is 49941, no count is 59

Test #5:

score: 0
Accepted
time: 127ms
memory: 10128kb

input:

1000
200 1000
42 68 2
101 170 2
79 159 2
65 106 3
82 28 2
92 196 3
28 37 1
5 103 1
93 183 1
117 119 3
48 127 3
139 70 2
68 100 2
95 104 1
123 134 1
65 142 2
54 69 3
45 63 1
38 60 3
142 130 2
117 36 3
43 89 2
41 143 2
49 47 1
91 130 2
151 7 1
194 149 1
24 85 2
157 41 2
177 132 2
145 40 3
124 138 2
11...

output:

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
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
...

result:

ok 1000 token(s): yes count is 1000, no count is 0

Test #6:

score: 0
Accepted
time: 125ms
memory: 9932kb

input:

1000
400 1000
372 17 2
321 365 2
357 136 3
185 231 1
359 328 1
142 164 1
75 280 2
55 6 2
37 329 3
259 302 3
222 304 3
70 130 1
114 120 2
314 291 1
396 41 2
77 111 2
35 275 3
348 145 3
346 2 2
351 158 2
173 172 2
68 122 1
147 11 3
160 391 1
30 360 2
120 174 3
145 296 3
170 311 1
107 313 1
282 211 1
3...

output:

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
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
...

result:

ok 1000 token(s): yes count is 1000, no count is 0

Test #7:

score: 0
Accepted
time: 128ms
memory: 9928kb

input:

1000
400 1000
372 17 2
321 365 2
357 136 2
185 231 2
359 328 2
142 164 2
75 280 2
55 6 1
37 329 1
259 302 2
222 304 2
70 130 2
114 120 2
314 291 1
396 41 2
77 111 2
35 275 2
348 145 1
346 2 1
351 158 1
173 172 1
68 122 1
147 11 1
160 391 2
30 360 1
120 174 2
145 296 2
170 311 2
107 313 1
282 211 1
3...

output:

No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
...

result:

ok 1000 token(s): yes count is 0, no count is 1000

Test #8:

score: 0
Accepted
time: 3ms
memory: 10352kb

input:

1
5002 8025
1 2 1
2 3 1
3 4 1
4 5 1
5 6 1
6 7 1
7 8 1
8 9 1
9 10 1
10 11 1
11 12 1
12 13 1
13 14 1
14 15 1
15 16 1
16 17 1
17 18 1
18 19 1
19 20 1
20 21 1
21 22 1
22 23 1
23 24 1
24 25 1
25 26 1
26 27 1
27 28 1
28 29 1
29 30 1
30 31 1
31 32 1
32 33 1
33 34 1
34 35 1
35 36 1
36 37 1
37 38 1
38 39 1
3...

output:

No

result:

ok NO

Test #9:

score: 0
Accepted
time: 3ms
memory: 8384kb

input:

1
5002 8241
1 2 1
2 3 1
3 4 1
4 5 1
5 6 1
6 7 1
7 8 1
8 9 1
9 10 1
10 11 1
11 12 1
12 13 1
13 14 1
14 15 1
15 16 1
16 17 1
17 18 1
18 19 1
19 20 1
20 21 1
21 22 1
22 23 1
23 24 1
24 25 1
25 26 1
26 27 1
27 28 1
28 29 1
29 30 1
30 31 1
31 32 1
32 33 1
33 34 1
34 35 1
35 36 1
36 37 1
37 38 1
38 39 1
3...

output:

No

result:

ok NO

Test #10:

score: 0
Accepted
time: 21ms
memory: 16744kb

input:

1
50002 80241
1 2 1
2 3 1
3 4 1
4 5 1
5 6 1
6 7 1
7 8 1
8 9 1
9 10 1
10 11 1
11 12 1
12 13 1
13 14 1
14 15 1
15 16 1
16 17 1
17 18 1
18 19 1
19 20 1
20 21 1
21 22 1
22 23 1
23 24 1
24 25 1
25 26 1
26 27 1
27 28 1
28 29 1
29 30 1
30 31 1
31 32 1
32 33 1
33 34 1
34 35 1
35 36 1
36 37 1
37 38 1
38 39 1...

output:

No

result:

ok NO

Test #11:

score: 0
Accepted
time: 19ms
memory: 18100kb

input:

1
50002 80241
41804 9985 3
41015 531 1
32475 43357 1
27804 45331 1
37830 10818 1
9140 8762 1
3221 23343 3
28197 44388 3
12185 41625 1
44450 9756 2
38350 14775 1
9757 19481 1
20858 17104 1
7807 24256 3
32044 37846 3
46885 27385 1
39738 9906 1
44158 35304 3
16289 43980 2
23066 24757 1
42969 19561 3
46...

output:

No

result:

ok NO

Test #12:

score: 0
Accepted
time: 201ms
memory: 47872kb

input:

1
455002 812001
313782 211383 2
408674 310967 1
3243 335360 3
401421 177274 3
308321 237341 2
96981 83503 3
72406 169080 3
33154 273727 1
213486 241588 3
45112 90708 1
445073 252383 1
337069 283893 1
183445 167972 1
147552 226440 1
139659 55742 3
237507 63881 1
315650 309664 1
25601 309502 3
103898 ...

output:

No

result:

ok NO

Test #13:

score: -100
Runtime Error

input:

1
550002 960001
457067 193767 1
342478 12620 1
457744 335514 1
539768 376061 1
138263 362120 3
470645 351694 2
378812 275543 3
433382 61920 3
80042 190753 1
416842 239041 3
210707 333641 1
136495 292903 3
231177 488035 1
161882 335528 1
109575 231095 1
460301 391728 1
482079 202050 1
267924 42252 1
...

output:


result: