Submission #1675657
Source Code Expand
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll ;
#define rep(i, a, b) for (int i = a; i <= b; ++ i)
const int N = 510, mo = 1000000007 ;
using namespace std ;
int n, m, col, e, ter[N], nxt[N], lnk[N], id[N], cnt, top, ans, d[N] ;
bool vis[N], ins[N], h[N] ;
int dfn[N], low[N], st[N] ;
struct edge {
int x, y ;
} E[N] ;
int gcd(int x, int y) {
return (y ? gcd(y, x % y) : x) ;
}
void add(int x, int y, int z) {
ter[++ e] = y, nxt[e] = lnk[x], lnk[x] = e, id[e] = z ;
}
inline int INP(int x) {
if (!h[x]) {
h[x] = true ;
d[++ d[0]] = x ;
return 1 ;
}
return 0 ;
}
inline void OUP() {
rep(i, 1, d[0]) {
h[d[i]] = false ;
}
}
inline int mul(int a, int b) {
int ans = 1, w = a % mo ;
for ( ; b; b /= 2) {
if (b & 1) ans = (ll) ans * w % mo ;
w = (ll) w * w % mo ;
}
return ans ;
}
inline int calc_cir(int x) {
int res = 0 ;
rep(i, 0, x - 1) {
res = (res + mul(col, gcd(i, x))) % mo ;
}
res = (ll) res * mul(x, mo - 2) % mo ;
return res ;
}
inline int C(int x, int y) {
int res = 1 ;
rep(i, 2, x) res = (ll) res * i % mo ;
rep(i, 2, y) res = (ll) res * mul(i, mo - 2) % mo ;
rep(i, 2, x - y) res = (ll) res * mul(i, mo - 2) % mo ;
return res ;
}
inline int calc_u(int x) {
return C(col + x - 1, col - 1) ;
}
void dfs(int p, int las) {
//printf("----- V : %d\n", p) ;
dfn[p] = low[p] = ++ cnt ;
for (int i = lnk[p]; i; i = nxt[i]) {
if (!dfn[ter[i]]) {
st[++ top] = id[i], ins[id[i]] = true, vis[id[i]] = false ;
dfs(ter[i], p) ;
low[p] = min(low[p], low[ter[i]]) ;
if (low[ter[i]] >= dfn[p]) {
int poi = 0, ed = 0 ;
d[0] = 0 ;
for ( ; ; ) {
poi += INP(E[st[top]].x) ;
poi += INP(E[st[top]].y) ;
++ ed ;
ins[st[top]] = false ;
-- top ;
if (st[top + 1] == id[i]) break ;
}
OUP() ;
if (poi == ed) ans = (ll) ans * calc_cir(ed) % mo /*, printf("Find ---- poi = %d ; ed = %d ; ans *= %d\n", poi, ed, calc_cir(ed)) */;
else ans = (ll) ans * calc_u(ed) % mo /*, printf("Find ---- poi = %d ; ed = %d ; ans *= %d\n", poi, ed, calc_u(ed))*/ ;
}
} else {
if (vis[id[i]]) {
vis[id[i]] = false ;
st[++ top] = id[i] ;
ins[id[i]] = true ;
}
if (ins[id[i]]) low[p] = min(low[p], dfn[ter[i]]) ;
}
}
}
int main() {
scanf("%d%d%d", &n, &m, &col) ;
int x, y ;
rep(i, 1, m) {
scanf("%d%d", &x, &y) ;
add(x, y, i), add(y, x, i) ;
E[i].x = x, E[i].y = y ;
}
memset(vis, true, sizeof(vis)) ;
memset(ins, false, sizeof(ins)) ;
ans = 1 ;
cnt = top = 0 ;
rep(i, 1, n) if (!dfn[i]) {
dfs(i, 0) ;
}
printf("%d\n", (ans + mo) % mo) ;
return 0 ;
}
Submission Info
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:106:32: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &n, &m, &col) ;
^
./Main.cpp:109:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &x, &y) ;
^
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
1300 / 1300 |
Status |
|
|
Set Name |
Test Cases |
Sample |
0_000.txt, 0_001.txt, 0_002.txt |
All |
0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt, 1_020.txt, 1_021.txt, 1_022.txt, 1_023.txt, 1_024.txt, 1_025.txt, 1_026.txt, 1_027.txt, 1_028.txt, 1_029.txt, 1_030.txt, 1_031.txt, 1_032.txt, 1_033.txt, 1_034.txt, 1_035.txt, 1_036.txt, 1_037.txt, 1_038.txt, 1_039.txt, 1_040.txt, 1_041.txt, 1_042.txt, 1_043.txt, 1_044.txt, 1_045.txt, 1_046.txt, 1_047.txt, 1_048.txt, 1_049.txt, 1_050.txt, 1_051.txt, 1_052.txt, 1_053.txt, 1_054.txt, 1_055.txt, 1_056.txt, 1_057.txt, 1_058.txt, 1_059.txt, 1_060.txt, 1_061.txt, 1_062.txt, 1_063.txt |
Case Name |
Status |
Exec Time |
Memory |
0_000.txt |
AC |
1 ms |
256 KB |
0_001.txt |
AC |
1 ms |
256 KB |
0_002.txt |
AC |
1 ms |
256 KB |
1_003.txt |
AC |
1 ms |
256 KB |
1_004.txt |
AC |
2 ms |
256 KB |
1_005.txt |
AC |
2 ms |
256 KB |
1_006.txt |
AC |
1 ms |
256 KB |
1_007.txt |
AC |
1 ms |
256 KB |
1_008.txt |
AC |
1 ms |
256 KB |
1_009.txt |
AC |
1 ms |
256 KB |
1_010.txt |
AC |
1 ms |
256 KB |
1_011.txt |
AC |
1 ms |
256 KB |
1_012.txt |
AC |
1 ms |
256 KB |
1_013.txt |
AC |
1 ms |
256 KB |
1_014.txt |
AC |
1 ms |
256 KB |
1_015.txt |
AC |
1 ms |
256 KB |
1_016.txt |
AC |
1 ms |
256 KB |
1_017.txt |
AC |
1 ms |
256 KB |
1_018.txt |
AC |
1 ms |
256 KB |
1_019.txt |
AC |
1 ms |
256 KB |
1_020.txt |
AC |
1 ms |
256 KB |
1_021.txt |
AC |
1 ms |
256 KB |
1_022.txt |
AC |
1 ms |
256 KB |
1_023.txt |
AC |
1 ms |
256 KB |
1_024.txt |
AC |
1 ms |
256 KB |
1_025.txt |
AC |
1 ms |
256 KB |
1_026.txt |
AC |
1 ms |
256 KB |
1_027.txt |
AC |
1 ms |
256 KB |
1_028.txt |
AC |
1 ms |
256 KB |
1_029.txt |
AC |
1 ms |
256 KB |
1_030.txt |
AC |
1 ms |
256 KB |
1_031.txt |
AC |
1 ms |
256 KB |
1_032.txt |
AC |
1 ms |
256 KB |
1_033.txt |
AC |
1 ms |
256 KB |
1_034.txt |
AC |
1 ms |
256 KB |
1_035.txt |
AC |
1 ms |
256 KB |
1_036.txt |
AC |
1 ms |
256 KB |
1_037.txt |
AC |
1 ms |
256 KB |
1_038.txt |
AC |
1 ms |
256 KB |
1_039.txt |
AC |
1 ms |
256 KB |
1_040.txt |
AC |
1 ms |
256 KB |
1_041.txt |
AC |
1 ms |
256 KB |
1_042.txt |
AC |
1 ms |
256 KB |
1_043.txt |
AC |
1 ms |
256 KB |
1_044.txt |
AC |
1 ms |
256 KB |
1_045.txt |
AC |
1 ms |
256 KB |
1_046.txt |
AC |
1 ms |
256 KB |
1_047.txt |
AC |
1 ms |
256 KB |
1_048.txt |
AC |
1 ms |
256 KB |
1_049.txt |
AC |
1 ms |
256 KB |
1_050.txt |
AC |
1 ms |
256 KB |
1_051.txt |
AC |
1 ms |
256 KB |
1_052.txt |
AC |
1 ms |
256 KB |
1_053.txt |
AC |
1 ms |
256 KB |
1_054.txt |
AC |
1 ms |
256 KB |
1_055.txt |
AC |
1 ms |
256 KB |
1_056.txt |
AC |
1 ms |
256 KB |
1_057.txt |
AC |
1 ms |
256 KB |
1_058.txt |
AC |
1 ms |
256 KB |
1_059.txt |
AC |
1 ms |
256 KB |
1_060.txt |
AC |
1 ms |
256 KB |
1_061.txt |
AC |
2 ms |
256 KB |
1_062.txt |
AC |
1 ms |
256 KB |
1_063.txt |
AC |
1 ms |
256 KB |