QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#426910 | #4194. Killjoys' Conference | rania__# | WA | 2ms | 12456kb | C++20 | 1.3kb | 2024-06-01 00:36:56 | 2024-06-01 00:36:57 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
vector<int>v[1000006];
bool vis[1000006];
int depth[1000006];
void dfs(int i,int dpth)
{
vis[i]=1;
depth[i]=dpth;
for(auto j:v[i])
{
if(!vis[j])
{
dfs(j,dpth+1);
}
}
}
int power(int b,int p,int m)
{
if(p == 0)return 1;
if(p == 1)return b;
int ret=power(b,p/2,m)%m;
ret*=ret;
ret%=m;
if(p%2 == 1)
{
ret*=b;
ret%=m;
}
return ret;
}
void solve()
{
int n,m,p;
cin>>n>>m>>p;
vector<pair<int,int>>edges;
for(int i=0;i<m;i++)
{
int a,b;
cin>>a>>b;
v[a].push_back(b);
v[b].push_back(a);
edges.push_back({a,b});
}
int cnt=0;
for(int i=1;i<=n;i++)
{
if(!vis[i])
{
dfs(i,0);
cnt++;
}
}
for(int i=0;i<edges.size();i++)
{
if(depth[edges[i].first]%2 == depth[edges[i].second]%2)
{
cout<<"impossible"<<endl;
return;
}
}
cout<<power(2,cnt-1,p)+1<<endl;
}
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t=1;
//cin>>t;
while(t--)
{
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3548kb
input:
4 2 11 1 2 3 4
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 2ms
memory: 3848kb
input:
5 2 3 1 2 3 4
output:
2
result:
ok single line: '2'
Test #3:
score: 0
Accepted
time: 2ms
memory: 3564kb
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: 3768kb
input:
100 0 13
output:
9
result:
ok single line: '9'
Test #5:
score: 0
Accepted
time: 2ms
memory: 12456kb
input:
1000000 0 999983
output:
131073
result:
ok single line: '131073'
Test #6:
score: -100
Wrong Answer
time: 0ms
memory: 3548kb
input:
5 0 17
output:
17
result:
wrong answer 1st lines differ - expected: '0', found: '17'