QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#146909 | #4194. Killjoys' Conference | xinying | WA | 413ms | 105656kb | C++14 | 1.8kb | 2023-08-22 17:26:21 | 2023-08-22 17:26:21 |
Judging History
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;
} else {
cout << "impossible";
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3876kb
input:
4 2 11 1 2 3 4
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3532kb
input:
5 2 3 1 2 3 4
output:
2
result:
ok single line: '2'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3592kb
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: 3812kb
input:
100 0 13
output:
9
result:
ok single line: '9'
Test #5:
score: 0
Accepted
time: 17ms
memory: 50156kb
input:
1000000 0 999983
output:
131073
result:
ok single line: '131073'
Test #6:
score: 0
Accepted
time: 1ms
memory: 3616kb
input:
5 0 17
output:
0
result:
ok single line: '0'
Test #7:
score: 0
Accepted
time: 1ms
memory: 3684kb
input:
6 0 11
output:
0
result:
ok single line: '0'
Test #8:
score: 0
Accepted
time: 413ms
memory: 105656kb
input:
910292 929828 296851369 138316 521196 344174 594024 83412 434709 773248 836155 238718 422888 306559 904462 267860 898937 413132 488904 377100 725377 280966 647857 194879 226916 46886 181828 211614 264486 597301 659354 211498 340231 131349 463058 218728 850468 112991 832910 311079 403177 94372 457800...
output:
impossible
result:
ok single line: 'impossible'
Test #9:
score: -100
Wrong Answer
time: 21ms
memory: 28668kb
input:
474415 39086 193520539 226365 326319 173587 188446 196237 384686 12130 438747 142687 240963 42823 198839 33523 441119 37690 269573 158873 264117 265666 307648 371107 470830 111014 416679 205426 259164 143776 337091 266405 399531 7332 293732 87282 131377 144755 269135 73861 213137 413795 429757 12293...
output:
79618820
result:
wrong answer 1st lines differ - expected: '24850764', found: '79618820'