QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#54607#4194. Killjoys' ConferenceT3alaadl3k2olyehymn3k#WA 7ms27860kbC++2.2kb2022-10-09 20:34:072022-10-09 20:34:08

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-09 20:34:08]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:27860kb
  • [2022-10-09 20:34:07]
  • 提交

answer

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define gtr(T) vector<T>,greater<T>

using namespace std;
using namespace __gnu_pbds;
template<class T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

void err(istream_iterator<string> it) {cerr << endl;}
template<typename T, typename... Args>void err(istream_iterator<string> it, T a, Args... args) {cerr << *it << " = " << a << endl;err(++it, args...);}

using ll  = long long;
using pii = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vector<int>>;


const int dx[] = {0, 0, 1,  -1, 1, -1,  1, -1};
const int dy[] = {1 , -1, 0, 0, 1, -1, -1,  1};


const int N = 1e6 + 5;
const int M = 1e3 + 5;
const int MOD = 100;

int n , m;

vector<int> adj[N];
int vis[N];
bool isCycle = false;
void addEdge(int u, int v){
    adj[u].emplace_back(v);
    adj[v].emplace_back(u);
}
bool dfs(int v) {
    vis[v] = 1;
    for (int u : adj[v]) {
        if (vis[u] == 0) {
            if (dfs(u))
                return true;
        } else if (vis[u] == 1) {
            return true;
        }
    }
    vis[v] = 2;
    return false;
}
int add(int a, int b, int p){
    return (1LL * a + b) % p;
}
int mul(int a, int b, int p){
    return (1LL * a * b) % p;
}
int fp(int b, int p, int m){
    int res = 1;
    while(p){
        if(p & 1)
            res = mul(res, b, m);
        b = mul(b,b, m);
        p >>= 1;
    }
    return res;
}
signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int p;
    cin >> n >> m >> p;
    int u, v;
    for(int i = 0; i < m; ++i){
        cin >> u >> v;
        addEdge(u,v);
    }
    int cnt = 0;
    for(int i = 1; i <= n; ++i){
        if(!vis[i]){
            cnt++;
            isCycle |= dfs(i);
        }
    }
    if(isCycle){
        cout << "impossible\n";
    }else{
        int ans = fp(2, cnt - 1, p);
        ans = add(ans, 1, p);
        cout << ans << '\n';
    }
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 7ms
memory: 27860kb

input:

4 2 11
1 2
3 4

output:

impossible

result:

wrong answer 1st lines differ - expected: '3', found: 'impossible'