DEVC++ process exited without return value 322212225725
1堆栈溢出
1.1运行数组越界,数组开的不够大
1.2不开眼把数组写在main函数里面找k
/*
链接:https://ac.nowcoder.com/acm/contest/5891/C
来源:牛客网
题目描述
YZ is the king of the kingdom. There are n cities in his kingdom. To celebrate the 50th anniversary of the founding of his country, YZ decided to distribute supplies as a reward to all the cities.
We all know that the further the city is from the capital (always at 1), the more it will cost to transport. We define K as the shortest distance between a city and the capital, and ignore the difference in distance between different cities(all is 1 unit). Cost from capital to the city is 2^K2
K
.
Now YZ gives you the map of his kingdom, and asks you if you can calculate the total cost.
(We guarantee that it is a connected graph.)
输入描述:
The first line contains two integers n and m (1 \le n \le 10^6,n-1 \le m \le min(2*10^6,(n-1)*n/2))(1≤n≤10
6
,n−1≤m≤min(2∗10
6
,(n−1)∗n/2)), which means there are n cities and m roads.
The next m lines contains two integers u and v, denoting there is a road connecting city u and city v.
输出描述:
Print the only line containing a single integer. It should be equal to the total cost mod 1e9+7.
示例1
输入
复制
3 2
1 2
2 3
输出
复制
6
示例2
输入
复制
7 6
1 2
1 3
1 4
3 5
3 6
4 7
输出
复制
18
*/
#include<stdio.h>
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int maxn=1e6+5;
ll dis[maxn]={0};
bool jilu[maxn]={false};
const ll mod=1e9+7;
vector<int> tu[maxn]; //以后数组都给我写到外面!!!
ll shuzu[maxn]={0};
ll binary(ll a,ll b,ll m)
{
if(b==0) return 1;
else if(b%2==1) return a*binary(a,b-1,m)%m;
else
{
ll temp=binary(a,b/2,m);
return temp*temp%m;
}
}
void bfs(int u){
queue<int> q;
q.push(u);
while(!q.empty()){
int a=q.front();
q.pop();
for(int b:tu[a]){
if(!jilu[b]) {
dis[b]=dis[a]+1;
jilu[b]=1;
q.push(b);
}
}
}
}
inline int read() {//啥子的读入挂(加快读入速度)
int s = 0, w = 1;
char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') w = -1;
for (; isdigit(c); c = getchar()) s = (s << 1) + (s << 3) + (c ^ 48);
return s * w;
}
int main()
{
int a,b;
a=read();
b=read();
for(int i=1;i<=b;i++)
{
int g,h;
g=read();
h=read();
tu[g].push_back(h);
tu[h].push_back(g);
}
bfs(1);
ll sum=0;
for(int i=2;i<=a;i++)
{
int xiabiao=dis[i];
if(shuzu[xiabiao]==0)
{
shuzu[xiabiao]=binary(2,xiabiao,mod);
sum=(sum+shuzu[xiabiao])%mod;
}
else sum=(sum+shuzu[xiabiao])%mod;
}
printf("%lld",sum);
return 0;
}