QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#229872#7640. Colorful Cyclesucup-team987#WA 258ms34320kbC++204.8kb2023-10-28 17:06:272023-10-28 17:06:54

Judging History

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

  • [2024-07-04 22:58:32]
  • hack成功,自动添加数据
  • (/hack/728)
  • [2023-10-28 17:06:54]
  • 评测
  • 测评结果:WA
  • 用时:258ms
  • 内存:34320kb
  • [2023-10-28 17:06:27]
  • 提交

answer

#include<iostream>
#include<algorithm>
#include<vector>
#include<cassert>
using namespace std;
#line 2 "graph/graph-template.hpp"

/**
 * @brief Graph Template(繧ー繝ゥ繝輔ユ繝ウ繝励Ξ繝シ繝・
 */
template< typename T = int >
struct Edge {
  int from, to;
  int idx;

  Edge() = default;

  Edge(int from, int to, int idx = -1) : from(from), to(to), idx(idx) {}

  operator int() const { return to; }
};

template< typename T = int >
struct Graph {
  vector< vector< Edge< T > > > g;
  int es;

  Graph() = default;

  explicit Graph(int n) : g(n), es(0) {}

  size_t size() const {
    return g.size();
  }

  void add_directed_edge(int from, int to) {
    g[from].emplace_back(from, to, es++);
  }

  void add_edge(int from, int to) {
    g[from].emplace_back(from, to, es);
    g[to].emplace_back(to, from, es++);
  }

  inline vector< Edge< T > > &operator[](const int &k) {
    return g[k];
  }

  inline const vector< Edge< T > > &operator[](const int &k) const {
    return g[k];
  }
};

template< typename T = int >
using Edges = vector< Edge< T > >;
#line 2 "graph/others/low-link.hpp"

#line 4 "graph/others/low-link.hpp"

/**
 * @brief Low Link(讖・髢「遽€轤ケ)
 * @see http://kagamiz.hatenablog.com/entry/2013/10/05/005213
 * @docs docs/low-link.md
 */
template< typename T = int >
struct LowLink : Graph< T > {
public:
  using Graph< T >::Graph;
  vector< int > ord, low, articulation;
  vector< Edge< T > > bridge;
  using Graph< T >::g;

  virtual void build() {
    used.assign(g.size(), 0);
    ord.assign(g.size(), 0);
    low.assign(g.size(), 0);
    int k = 0;
    for(int i = 0; i < (int) g.size(); i++) {
      if(!used[i]) k = dfs(i, k, -1);
    }
  }

  explicit LowLink(const Graph< T > &g) : Graph< T >(g) {}

private:
  vector< int > used;

  int dfs(int idx, int k, int par) {
    used[idx] = true;
    ord[idx] = k++;
    low[idx] = ord[idx];
    bool is_articulation = false, beet = false;
    int cnt = 0;
    for(auto &to : g[idx]) {
      if(to == par && !exchange(beet, true)) {
        continue;
      }
      if(!used[to]) {
        ++cnt;
        k = dfs(to, k, idx);
        low[idx] = min(low[idx], low[to]);
        is_articulation |= par >= 0 && low[to] >= ord[idx];
        if(ord[idx] < low[to]) bridge.emplace_back(to);
      } else {
        low[idx] = min(low[idx], ord[to]);
      }
    }
    is_articulation |= par == -1 && cnt > 1;
    if(is_articulation) articulation.push_back(idx);
    return k;
  }
};
#line 3 "graph/connected-components/bi-connected-components.hpp"

template< typename T = int >
struct BiConnectedComponents : LowLink< T > {
public:
  using LowLink< T >::LowLink;
  using LowLink< T >::g;
  using LowLink< T >::ord;
  using LowLink< T >::low;

  vector< vector< Edge< T > > > bc;

  void build() override {
    LowLink< T >::build();
    used.assign(g.size(), 0);
    for(int i = 0; i < (int)used.size(); i++) {
      if(!used[i]) dfs(i, -1);
    }
  }

  explicit BiConnectedComponents(const Graph< T > &g) : Graph< T >(g) {}

private:
  vector< int > used;
  vector< Edge< T > > tmp;

  void dfs(int idx, int par) {
    used[idx] = true;
    bool beet = false;
    for(auto &to : g[idx]) {
      if(to == par && !exchange(beet, true)) continue;
      if(!used[to] || ord[to] < ord[idx]) {
        tmp.emplace_back(to);
      }
      if(!used[to]) {
        dfs(to, idx);
        if(low[to] >= ord[idx]) {
          bc.emplace_back();
          for(;;) {
            auto e = tmp.back();
            bc.back().emplace_back(e);
            tmp.pop_back();
            if(e.idx == to.idx) break;
          }
        }
      }
    }
  }
};
int U[1<<20],V[1<<20],COL[1<<20];
vector<pair<int,int> >G[1<<20];
int TM[1<<20];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int T;cin>>T;
	for(;T--;)
	{
		int N,M;
		cin>>N>>M;
		BiConnectedComponents<>B(N);
		for(int i=0;i<M;i++)
		{
			cin>>U[i]>>V[i]>>COL[i];
			U[i]--,V[i]--;
			B.add_edge(U[i],V[i]);
		}
		B.build();
		for(int i=0;i<N;i++)TM[i]=-1;
		bool ans=false;
		for(int i=0;i<B.bc.size();i++)
		{
			vector<int>VS;
			int t=0;
			for(int j=0;j<B.bc[i].size();j++)
			{
				int id=B.bc[i][j];
				if(TM[U[id]]<i)
				{
					TM[U[id]]=i;
					VS.push_back(U[id]);
				}
				if(TM[V[id]]<i)
				{
					TM[V[id]]=i;
					VS.push_back(V[id]);
				}
				G[U[id]].push_back(make_pair(V[id],COL[id]));
				G[V[id]].push_back(make_pair(U[id],COL[id]));
				t|=1<<COL[id]-1;
			}
			if(t==7)
			{
				int cnt=0;
				for(int v:VS)
				{
					int x=0;
					for(pair<int,int>e:G[v])x|=1<<e.second-1;
					if(x==1||x==2||x==4);
					else cnt++;
				}
				if(cnt>=3)ans=true;
			}
			for(int v:VS)G[v].clear();
		}
		cout<<(ans?"Yes\n":"No\n");
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 258ms
memory: 34284kb

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
No
Yes
No
Yes
Yes
Yes
Yes
Yes
No
Yes
No
Yes
Yes
No
No
No
No
Yes
Yes
No
No
Yes
Yes
Yes
Yes
No
No
Yes
Yes
No
Yes
Yes
Yes
No
No
No
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
Yes
No
No
No
Yes
No
No
Yes
No
No
Yes
Yes
Yes
Yes
Yes
No
Yes
No
Yes
Yes
Yes
Yes
No
Yes
No
No
Yes
No
Yes
No
Yes
Yes
Yes
Yes
No
No
Yes
Y...

result:

wrong answer expected YES, found NO [3rd token]