QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#230012 | #7640. Colorful Cycles | ucup-team987# | Compile Error | / | / | C++20 | 4.8kb | 2023-10-28 17:24:39 | 2024-10-14 08:01:26 |
Judging History
你现在查看的是最新测评结果
- [2024-10-14 08:01:26]
- 管理员手动重测本题所有获得100分的提交记录
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2024-07-04 22:58:32]
- hack成功,自动添加数据
- (/hack/728)
- [2023-10-28 17:24:39]
- 提交
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].idx;
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
graph/others/low-link.hpp: In member function ‘int LowLink<T>::dfs(int, int, int)’: graph/others/low-link.hpp:40:24: error: there are no arguments to ‘exchange’ that depend on a template parameter, so a declaration of ‘exchange’ must be available [-fpermissive] graph/others/low-link.hpp:40:24: note: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of an undeclared name is deprecated) graph/connected-components/bi-connected-components.hpp: In member function ‘void BiConnectedComponents<T>::dfs(int, int)’: graph/connected-components/bi-connected-components.hpp:32:24: error: there are no arguments to ‘exchange’ that depend on a template parameter, so a declaration of ‘exchange’ must be available [-fpermissive] graph/connected-components/bi-connected-components.hpp: In instantiation of ‘void BiConnectedComponents<T>::dfs(int, int) [with T = int]’: graph/connected-components/bi-connected-components.hpp:18:20: required from ‘void BiConnectedComponents<T>::build() [with T = int]’ graph/connected-components/bi-connected-components.hpp:70:10: required from here graph/connected-components/bi-connected-components.hpp:32:32: error: ‘exchange’ was not declared in this scope graph/connected-components/bi-connected-components.hpp:3:1: note: ‘std::exchange’ is defined in header ‘<utility>’; did you forget to ‘#include <utility>’? graph/others/low-link.hpp: In instantiation of ‘int LowLink<T>::dfs(int, int, int) [with T = int]’: graph/others/low-link.hpp:24:24: required from ‘void LowLink<T>::build() [with T = int]’ graph/connected-components/bi-connected-components.hpp:15:24: required from ‘void BiConnectedComponents<T>::build() [with T = int]’ graph/connected-components/bi-connected-components.hpp:70:10: required from here graph/others/low-link.hpp:40:32: error: ‘exchange’ was not declared in this scope graph/others/low-link.hpp:2:1: note: ‘std::exchange’ is defined in header ‘<utility>’; did you forget to ‘#include <utility>’?