QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#54677#4194. Killjoys' ConferenceAs3b_team_f_masr#RE 3ms3780kbC++1.1kb2022-10-10 03:39:112022-10-10 03:39:14

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-10 03:39:14]
  • 评测
  • 测评结果:RE
  • 用时:3ms
  • 内存:3780kb
  • [2022-10-10 03:39:11]
  • 提交

answer

#include <bits/stdc++.h>

typedef long double ld;
typedef long long ll;
using namespace std;
int di[] = {1, 0, -1, -1, 0, 1, -1, 1};
int dj[] = {1, 1, 0, -1, -1, 0, 1, -1};
const ll oo = 1e18, MOD = 998244353;
const int N = 2005, M = 350;
const ld PI = acos(-1.0), EPS = 1e-9;

int n, m, p, c[N], vis[N];
vector<int> v[N];
bool no;

void dfs(int node) {
    vis[node] = 1;
    for (auto x:v[node]) {
        if (!vis[x]) c[x] = !c[node], dfs(x);
        else if (c[x] == c[node]) no = 1;
    }
}

//#define endl '\n'
int main() {
    //ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    //freopen("farm.in", "r", stdin);
    //memset(dp, -1, sizeof dp);
    cin >> n >> m >> p;
    while (m--) {
        int x, y;
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (!vis[i]) dfs(i), ans++;
    }
    ll ans2 = 1;
    for (int i = 1; i < ans; i++) ans2 = (ans2 * 2) % p;
    if (no) return !(cout << "impossible");
    else cout << (ans2 + 1 + p) % p;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 2 11
1 2
3 4

output:

3

result:

ok single line: '3'

Test #2:

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

input:

5 2 3
1 2
3 4

output:

2

result:

ok single line: '2'

Test #3:

score: 0
Accepted
time: 3ms
memory: 3572kb

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: 3780kb

input:

100 0 13

output:

9

result:

ok single line: '9'

Test #5:

score: -100
Runtime Error

input:

1000000 0 999983

output:


result: