QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#136443#4194. Killjoys' ConferenceRetiredButNotTired#TL 1ms3516kbC++201.3kb2023-08-08 19:29:412023-08-08 19:29:43

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-08 19:29:43]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3516kb
  • [2023-08-08 19:29:41]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int tt, tc;

void solve() {
    int n, m, p;
    cin >> n >> m >> p;
    vector<vector<int>> g(n);
    vector<int> vis(n);
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    auto process = [&](int v) {
        queue<int> q;
        q.push(v);
        vector<int> color(n);
        color[v] = 1;
        while (!q.empty()) {
            int c = q.front();
            q.pop();
            vis[c] = 1;
            for (int u : g[c]) {
                if (color[u]) {
                    if (color[u] != 3 - color[c]) return false;
                } else {
                    color[u] = 3 - color[c];
                    q.push(u);
                }
            }
        }
        return true;
    };

    int ans = 1;
    int take = 0;
    for (int i = 0; i < n; i++) if (!vis[i]) {
        if (!process(i)) return void(cout << "impossible" << "\n");
        if (take) ans = (ans + ans) % p;
        take = 1;
    }

    cout << (ans + 1) % p << "\n";
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    tt = 1, tc = 1; // cin >> tt;
    while (tt--) solve(), tc++;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3464kb

input:

4 2 11
1 2
3 4

output:

3

result:

ok single line: '3'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3516kb

input:

5 2 3
1 2
3 4

output:

2

result:

ok single line: '2'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3456kb

input:

3 3 11
1 2
2 3
3 1

output:

impossible

result:

ok single line: 'impossible'

Test #4:

score: 0
Accepted
time: 1ms
memory: 3456kb

input:

100 0 13

output:

9

result:

ok single line: '9'

Test #5:

score: -100
Time Limit Exceeded

input:

1000000 0 999983

output:


result: