QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#146908#4194. Killjoys' ConferencexinyingWA 1ms3452kbC++141.8kb2023-08-22 17:25:562023-08-22 17:25:57

Judging History

This is the latest submission verdict.

  • [2023-08-22 17:25:57]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3452kb
  • [2023-08-22 17:25:56]
  • Submitted

answer

#include <bits/stdc++.h>

using namespace std;

#define int long long 
const int N = 1e6 + 10;
using ll = long long;
int fa[N];
ll poww(ll a, ll b, ll p){
    ll res = 1 % p;
    while(b){
        if(b & 1) res = res * a % p;
        a = a * a % p;
        b >>= 1;
    }
    return res;
}
int find(int x) {
    return fa[x] == x ? x : fa[x] = find(fa[x]);
}

void merge(int x, int y) {
    int fx = fa[x], fy = fa[y];
    fa[fx] = fy;
}
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m, p;
    cin >> n >> m >> p;
    for (int i = 1; i <= n; i++) {
        fa[i] = i;
    }
    std::vector<std::vector<int>> g(n + 1);
    for (int i = 1; i <= m; i++) {
        int x, y;
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }


    bool ok = true;
    std::vector<int> col(n + 1, -1);
    function<void(int, int)> dfs = [&](int x, int f) {
        for (auto y : g[x]) {
            if (y == f) continue;
            if (col[y] != -1 && (col[x] == col[y])) {
                ok = false;
            }

            if (col[y] == -1) {
                col[y] = col[x] ^ 1;
                dfs(y, x);
                merge(x, y);
            }
        }
    };

    int res = 1;
    for (int i = 1; i <= n; i++) {
        if (col[i] == -1) {
            col[i] = 0;
            dfs(i, -1);
        }
    }

    std::vector<int> vis(n + 1);
    int flag = 0;
    for (int i = 1; i <= n; i++) {
        if (!vis[find(i)]) {
            if (flag)
            res = res * 2 % p;
            vis[find(i)] = 1;
            flag =1 ;
        }
    }

    res = (res + 1) % p;
    if (ok) {
        cout << (res + 1) % p;
    } else {
        cout << "impossible";
    }
    
}       

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3452kb

input:

4 2 11
1 2
3 4

output:

4

result:

wrong answer 1st lines differ - expected: '3', found: '4'