QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#121680 | #856. Cactus | karuna# | WA | 71ms | 21892kb | C++17 | 2.0kb | 2023-07-08 17:31:16 | 2023-07-08 17:31:49 |
Judging History
answer
#include <bits/stdc++.h>
#define ff first
#define ss second
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 4e5;
const ll MOD = 1e9+7;
int TC, N, M;
ll K;
vector<int> adj[MAXN+10];
ll dp[MAXN+10], dp2[MAXN+10];
int cnt;
int dfn[MAXN+10], low[MAXN+10];
void dfs(int now, int bef)
{
dfn[now]=++cnt;
low[now]=dfn[now];
for(int nxt : adj[now])
{
if(nxt==bef) continue;
if(dfn[nxt]==0)
{
dfs(nxt, now);
low[now]=min(low[now], low[nxt]);
}
else
{
low[now]=min(low[now], dfn[nxt]);
}
}
}
int bcnt;
bool vis[MAXN+10];
int A[MAXN+10];
void bcc(int now, int bef, int col)
{
vis[now]=true;
A[col]++;
for(int nxt : adj[now])
{
if(nxt==bef) continue;
if(vis[nxt]) continue;
if(low[nxt]>=dfn[nxt]) bcc(nxt, now, ++bcnt);
else bcc(nxt, now, col);
}
}
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
scanf("%d", &TC);
while(TC--)
{
scanf("%d%d%lld", &N, &M, &K);
for(int i=1; i<=M; i++)
{
int u, v;
scanf("%d%d", &u, &v);
adj[u].push_back(v);
adj[v].push_back(u);
}
dp[1]=K; dp2[1]=K-1;
dp[2]=K*(K-1)%MOD; dp2[2]=(K-1)*(K-1)%MOD;
ll t=1;
for(int i=3; i<=N; i++)
{
t=t*(K-1)%MOD;
dp[i]=K*t%MOD-dp[i];
dp2[i]=(K-1)*t%MOD-dp2[i];
dp[i]=(dp[i]%MOD+MOD)%MOD;
dp2[i]=(dp2[i]%MOD+MOD)%MOD;
}
dfs(1, 1);
bcc(1, 1, ++bcnt);
ll ans=dp[A[1]];
for(int i=2; i<=bcnt; i++) ans=ans*dp2[A[i]]%MOD;
printf("%lld\n", ans);
for(int i=1; i<=N; i++)
{
adj[i].clear();
dfn[i]=low[i]=vis[i]=0;
A[i]=0;
dp[i]=0; dp2[i]=0;
}
cnt=0; bcnt=0;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 21892kb
input:
2 2 1 100 1 2 6 7 3 1 2 2 3 3 1 4 5 5 6 6 4 1 4
output:
9900 24
result:
ok 2 number(s): "9900 24"
Test #2:
score: -100
Wrong Answer
time: 71ms
memory: 20636kb
input:
50000 9 10 4 4 7 5 2 1 5 7 3 9 6 8 3 3 2 9 1 4 8 6 2 10 11 4 4 1 1 3 5 1 10 9 8 4 1 6 7 9 7 10 8 1 1 9 10 2 10 10 4 7 5 6 9 5 1 9 7 10 9 4 9 5 10 2 3 3 7 3 8 9 10 4 3 9 3 7 5 4 6 2 1 9 6 5 4 2 9 8 5 1 7 8 9 9 4 9 4 4 1 6 3 8 7 2 9 6 7 1 8 6 9 5 2 10 11 4 7 8 6 2 9 10 7 2 2 4 4 7 3 7 3 1 10 6 6 9 5 1...
output:
2916 8748 26244 2916 8748 8748 8748 8748 26244 8748 8748 8748 8748 2916 2916 26244 8748 2916 8748 8748 8748 8748 8748 26244 8748 2916 8748 7290 8748 8748 26244 2916 8748 8748 8748 599760 26244 8748 26244 8748 26244 2916 8748 8748 8748 8748 8748 8748 26244 8748 26244 8748 8748 26244 8748 2916 2916 87...
result:
wrong answer 1st numbers differ - expected: '15120', found: '2916'