QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#54677 | #4194. Killjoys' Conference | As3b_team_f_masr# | RE | 3ms | 3780kb | C++ | 1.1kb | 2022-10-10 03:39:11 | 2022-10-10 03:39:14 |
Judging History
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