QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#229201#7640. Colorful Cyclesucup-team180#WA 249ms3484kbC++173.3kb2023-10-28 15:25:202023-10-28 15:25:21

Judging History

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

  • [2024-07-04 22:58:32]
  • hack成功,自动添加数据
  • (/hack/728)
  • [2023-10-28 15:25:21]
  • 评测
  • 测评结果:WA
  • 用时:249ms
  • 内存:3484kb
  • [2023-10-28 15:25:20]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
struct extended_block_cut_tree{
  int N, cnt;
  vector<vector<int>> G;
  extended_block_cut_tree(vector<vector<pair<int, int>>> &E){
    N = E.size();
    vector<int> next(N, -1);
    vector<int> d(N, -1);
    vector<int> imos(N, 0);
    for (int i = 0; i < N; i++){
      if (d[i] == -1){
        d[i] = 0;
        dfs1(E, next, d, imos, i);
      }
    }
    cnt = 0;
    G.resize(N + 1);
    vector<bool> used(N, false);
    for (int i = 0; i < N; i++){
      if (d[i] == 0){
        dfs2(E, d, imos, used, cnt, i);
      }
      if (E[i].empty()){
        G[i].push_back(N + cnt);
        G[N + cnt].push_back(i);
        cnt++;
        G.push_back({});
      }
    }
    G.pop_back();
  }
  void dfs1(vector<vector<pair<int, int>>> &E, vector<int> &next, vector<int> &d, vector<int> &imos, int v){
    for (pair<int, int> e : E[v]){
      int w = e.second;
      if (d[w] == -1){
        d[w] = d[v] + 1;
        next[v] = w;
        dfs1(E, next, d, imos, w);
        imos[v] += imos[w];
      } else if (d[w] < d[v] - 1){
        imos[v]++;
        imos[next[w]]--;
      }
    }
  }
  void dfs2(vector<vector<pair<int, int>>> &E, vector<int> &d, vector<int> &imos, vector<bool> &used, int b, int v){
    used[v] = true;
    bool ok = false;
    for (pair<int, int> e : E[v]){
      int w = e.second;
      if (d[w] == d[v] + 1 && !used[w]){
        if (imos[w] > 0){
          if (!ok){
            ok = true;
            G[v].push_back(N + b);
            G[N + b].push_back(v);
          }
          dfs2(E, d, imos, used, b, w);
        } else {
          G[v].push_back(N + cnt);
          G[N + cnt].push_back(v);
          cnt++;
          G.push_back({});
          dfs2(E, d, imos, used, cnt - 1, w);
        }
      }
    }
    if (!ok && d[v] > 0){
      G[v].push_back(N + b);
      G[N + b].push_back(v);
    }
  }
  int size(){
    return G.size();
  }
  vector<int> &operator [](int v){
    return G[v];
  }
};
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  for (int i = 0; i < t; i++){
    int n, m;
    cin >> n >> m;
    vector<vector<pair<int, int>>> E(n);
    for (int j = 0; j < m; j++){
      int x, y, z;
      cin >> x >> y >> z;
      x--;
      y--;
      z--;
      E[x].push_back(make_pair(z, y));
      E[y].push_back(make_pair(z, x));
    }
    extended_block_cut_tree BCT(E);
    int V = BCT.size();
    vector<int> p(V, -1);
    vector<int> d(V, 0);
    queue<int> Q;
    Q.push(0);
    while (!Q.empty()){
      int v = Q.front();
      Q.pop();
      for (int w : BCT[v]){
        if (w != p[v]){
          p[w] = v;
          d[w] = d[v] + 1;
          Q.push(w);
        }
      }
    }
    vector<int> mask(V, 0);
    for (int j = 0; j < n; j++){
      for (pair<int, int> e : E[j]){
        int c = e.first;
        int k = e.second;
        if (d[j] == d[k] + 2){
          mask[p[j]] |= 1 << c;
        } else {
          mask[p[k]] |= 1 << c;
        }
      }
    }
    bool ok = false;
    for (int j = n; j < V; j++){
      if (mask[j] == 7){
        ok = true;
      }
    }
    if (ok){
      cout << "Yes" << '\n';
    } else {
      cout << "No" << '\n';
    }
  }
}

详细

Test #1:

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

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: 249ms
memory: 3484kb

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