QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#463300#7640. Colorful CyclesAlishWA 7ms55852kbC++173.1kb2024-07-04 17:20:342024-07-04 17:20:35

Judging History

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

  • [2024-07-04 22:58:32]
  • hack成功,自动添加数据
  • (/hack/728)
  • [2024-07-04 17:20:35]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:55852kb
  • [2024-07-04 17:20:34]
  • 提交

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;
            int cnt=0; 
            for (auto pp: C[i]) if(__builtin_popcount(pp.S)>1){
                x|=pp.S;
                cnt++; 
            }
            if(x==7 && cnt==2)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: 0
Wrong Answer
time: 7ms
memory: 55852kb

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:

No
No

result:

wrong answer expected YES, found NO [1st token]