QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#463295 | #7640. Colorful Cycles | Alish | WA | 170ms | 58096kb | C++17 | 3.0kb | 2024-07-04 17:07:39 | 2024-07-04 17:07:39 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define F first
#define S second
#define pb push_back
#define endl '\n'
#define Mp make_pair
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " = " << x << endl;
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("tests.in" , "r" , stdin) ;
ll mod = 1e9+7;
const int N = 1e6+23;
vector<pii> g[N];
int h[N], vis[N];
int col[N];
int dp[N];
int n, m;
vector<int> st;
int c;
vector<pii> C[N];
void dfs(int v, int p=0){
dp[v]=h[v];
vis[v]=1;
for (auto pp: g[v]){
int u=pp.F, w=pp.S;
if(u==p) continue;
if(vis[u]){
dp[v]=min(dp[v], h[u]);
}
else{
h[u]=h[v]+1;
int sz=st.size();
dfs(u);
dp[v]=min(dp[v], dp[u]);
if(dp[u]==h[v]){
c++;
while(st.size()!=sz){
C[c].pb({st.back(), 0});
col[st.back()]=c;
st.pop_back();
}
C[c].pb({v, 0});
}
}
}
if(dp[v]<h[v]) st.pb(v);
}
void DFS(int v, int p=0){
vis[v]=1;
for (auto pp: g[v]){
int u=pp.F, w=pp.S;
if(u==p) continue;
if(vis[u]){
if(h[u]>h[v] && dp[u]<h[u]){
int t=lower_bound(all(C[col[u]]), Mp(u, 0))-C[col[u]].begin();
C[col[u]][t].S|=(1<<w);
t=lower_bound(all(C[col[u]]), Mp(v, 0))-C[col[u]].begin();
C[col[u]][t].S|=(1<<w);
}
}
else{
DFS(u, v);
if(dp[u]<h[u]){
int t=lower_bound(all(C[col[u]]), Mp(u, 0))-C[col[u]].begin();
C[col[u]][t].S|=(1<<w);
t=lower_bound(all(C[col[u]]), Mp(v, 0))-C[col[u]].begin();
C[col[u]][t].S|=(1<<w);
}
}
}
}
int main()
{
fast_io
int T; cin>>T;
while(T--){
cin>>n>>m;
for (int i=0; i<m; i++){
int v, u, w; cin>>v>>u>>w;
w--;
g[v].pb({u, w});
g[u].pb({v, w});
}
dfs(1);
for (int i=1; i<=c; i++) sort(all(C[i]));
for (int i=1; i<=n; i++) vis[i]=0;
DFS(1);
int f=0;
for (int i=1; i<=c; i++){
int x=0;
for (auto pp: C[i]) if(__builtin_popcount(pp.S)>1) x|=pp.S;
if(x==7)f=1;
}
if(f)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
for (int i=1; i<=c; i++) C[i].clear();
for (int i=1; i<=n; i++){
g[i].clear();
vis[i]=0;
h[i]=0;
dp[i]=0;
col[i]=0;
}
st.clear();
c=0;
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 7ms
memory: 58096kb
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: 170ms
memory: 56116kb
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]