QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#54676#4188. Excursion to PorvooAs3b_team_f_masr#WA 3ms3628kbC++1.1kb2022-10-10 03:38:012022-10-10 03:38:02

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:38:02]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3628kb
  • [2022-10-10 03:38:01]
  • 提交

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: 0
Wrong Answer
time: 3ms
memory: 3628kb

input:

2 2
1 100 300
1 1 30
5
400
500
300
20
1

output:

impossible

result:

wrong answer 2nd lines differ - expected: 'impossible', found: ''