QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#597264#7640. Colorful Cyclesrotcar07WA 131ms11996kbC++201.5kb2024-09-28 17:24:512024-09-28 17:24:51

Judging History

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

  • [2024-09-28 17:24:51]
  • 评测
  • 测评结果:WA
  • 用时:131ms
  • 内存:11996kb
  • [2024-09-28 17:24:51]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
constexpr int maxn=1e6+5;
int dfn[maxn],low[maxn],tim,top,stk[maxn],n,m,col[maxn];
vector<pair<int,int>> e[maxn];vector<vector<int> >cc;
bool vis[maxn];
#define pb push_back
void dfs(int p,int f){
    int cnt=0;dfn[p]=low[p]=++tim;stk[++top]=p;
    for(auto [x,cinema]:e[p]){
        if(x==f) continue;
        if(dfn[x]) low[p]=min(low[p],dfn[x]);
        else{
            dfs(x,p);
            low[p]=min(low[p],low[x]);
            if(low[x]>=dfn[p]){
                vector<int> tmp;
                while(stk[top+1]!=x) tmp.pb(stk[top--]);
                tmp.pb(p);cc.pb(tmp);
            }
            cnt++;
        }
    }
    if(!cnt&&!f){
        vector<int> tmp;tmp.pb(p);
        cc.pb(tmp);
    }
}
inline void solve(){
    cin>>n>>m;tim=0;cc.clear();
    for(int i=1;i<=n;i++) e[i].clear(),dfn[i]=low[i]=0;
    for(int i=1,u,v;i<=m;i++) cin>>u>>v>>col[i],e[u].emplace_back(v,i),e[v].emplace_back(u,i);
    for(int i=1;i<=n;i++) if(!dfn[i]) dfs(i,0);
    for(auto x:cc){
        int msk=0,cnt=0;
        for(auto y:x) vis[y]=1;
        for(auto y:x){
            int w=0;
            for(auto [z,id]:e[y])if(vis[z]) w|=1<<col[id]-1;
            msk|=w,cnt+=(__builtin_popcount(w)>1);
        }
        for(auto y:x) vis[y]=0;
        if(msk==7&&cnt>=3) return puts("Yes"),void();
    }
    puts("No");
}
int main(){
    std::ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;cin>>t;
    while(t--) solve();
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 11736kb

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: 131ms
memory: 11996kb

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 YES, found NO [167th token]