QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#136443 | #4194. Killjoys' Conference | RetiredButNotTired# | TL | 1ms | 3516kb | C++20 | 1.3kb | 2023-08-08 19:29:41 | 2023-08-08 19:29:43 |
Judging History
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++;
}
Details
Tip: Click on the bar to expand more detailed information
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