322212225725这串数字是我的宿敌

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;
}

1.3数组越界

1.4指针指到他不该指的地方了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值