当前位置:网站首页>dijikstra(先预处理)+dfs,relocation truncated to fit
dijikstra(先预处理)+dfs,relocation truncated to fit
2022-07-26 04:11:00 【Selvaggia】
全局变量(数组)开大了
本来想搞个dist【N】[N]
/tmp/cccMPc7i.o: In function `dijikstra(int)':
a.cpp:(.text+0xb3): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/cccMPc7i.o
a.cpp:(.text+0xe3): relocation truncated to fit: R_X86_64_32S against symbol `vis' defined in .bss section in /tmp/cccMPc7i.o
a.cpp:(.text+0x154): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/cccMPc7i.o
a.cpp:(.text+0x1a2): relocation truncated to fit: R_X86_64_32S against symbol `vis' defined in .bss section in /tmp/cccMPc7i.o
a.cpp:(.text+0x1ba): relocation truncated to fit: R_X86_64_32S against symbol `vis' defined in .bss section in /tmp/cccMPc7i.o
/tmp/cccMPc7i.o: In function `dfs(int, int, int)':
a.cpp:(.text+0x378): relocation truncated to fit: R_X86_64_32S against symbol `st' defined in .bss section in /tmp/cccMPc7i.o
a.cpp:(.text+0x38a): relocation truncated to fit: R_X86_64_32S against symbol `st' defined in .bss section in /tmp/cccMPc7i.o
a.cpp:(.text+0x3f6): relocation truncated to fit: R_X86_64_32S against symbol `st' defined in .bss section in /tmp/cccMPc7i.o
/tmp/cccMPc7i.o: In function `main':
a.cpp:(.text+0x419): relocation truncated to fit: R_X86_64_32 against symbol `n' defined in .bss section in /tmp/cccMPc7i.o
a.cpp:(.text+0x428): relocation truncated to fit: R_X86_64_32 against symbol `m' defined in .bss section in /tmp/cccMPc7i.o
a.cpp:(.text+0x46f): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status
#include <iostream>
#include <queue>
using namespace std;
#define inf 0x3f3f3f3f
#define pii pair<int,int>
const int N=5e4+10;
const int M=1e5+5;
int id[10];
struct edge{
int to,nxt,w;
}e[M<<1];
int head[N];
int cnt;
void add(int u,int v,int w){
e[++cnt].w=w;
e[cnt].to=v;
e[cnt].nxt=head[u];
head[u]=cnt;
}
int dist[10][N];
bool vis[N];
int n,m;
void dijikstra(int s){
for(int i=1;i<=n;i++){
dist[s][i]=inf;
vis[i]=false;
}
priority_queue<pii, vector<pii> ,greater<pii> > Q;
Q.push({
0,s});
dist[s][s]=0;
for(int k=0;k<n;k++){
if(Q.empty())break;
pii t=Q.top(); Q.pop();
int v=t.second;
if(vis[v]){
k--;
continue;
}
vis[v]=1;
for(int i=head[v];i;i=e[i].nxt){
int to=e[i].to;
int w=e[i].w;
if(dist[s][to]>dist[s][v]+w){
dist[s][to]=dist[s][v]+w;
Q.push({
dist[s][to],to});
}
}
}
}
bool st[10];
int dfs(int p,int station,int dis){
if(station==5)return dis;
int res=inf;
for(int i=1;i<=5;i++){
if(!st[i]){
st[i]=true;
res=min(res,dfs(id[i],station+1,dis+dist[p][id[i]]));
st[i]=false;
}
}
return res;
}
int main(int argc, char** argv) {
cin>>n>>m;
id[0]=1;//佳佳家
for(int i=1;i<=5;i++)cin>>id[i];
int u,v,w;
while(m--){
cin>>u>>v>>w;
add(u,v,w);
add(v,u,w);
}
for(int i=0;i<=5;i++)dijikstra(id[i]);
cout<<dfs(1,0,0); //此时在何地,到了多少个车站 ,已经花了多少时间
return 0;
}
在这个样例出现 Segmentation Fault
11 15
11 4 9 10 8
1 3 7
1 5 5
1 4 10
1 2 6
9 5 3
5 6 8
6 3 7
3 2 2
2 8 5
8 4 8
3 8 8
2 7 11
6 10 20
10 7 12
4 11 30
原来是dist[][]存的是站点到站点,站点编号可不止10
只能存 必访站点的编号(0~5)才合理且不超内存
#include <iostream>
#include <queue>
using namespace std;
#define inf 0x3f3f3f3f
#define pii pair<int,int>
const int N=5e4+10;
const int M=1e5+5;
int id[10];
struct edge{
int to,nxt,w;
}e[M<<1];
int head[N];
int cnt;
void add(int u,int v,int w){
e[++cnt].w=w;
e[cnt].to=v;
e[cnt].nxt=head[u];
head[u]=cnt;
}
int dist[10][N];
bool vis[N];
int n,m;
void dijikstra(int s,int sg){
for(int i=1;i<=n;i++){
dist[sg][i]=inf;
vis[i]=false;
}
priority_queue<pii, vector<pii> ,greater<pii> > Q;
Q.push({
0,s});
dist[sg][s]=0;
for(int k=0;k<n;k++){
if(Q.empty())break;
pii t=Q.top(); Q.pop();
int v=t.second;
if(vis[v]){
k--;
continue;
}
vis[v]=1;
for(int i=head[v];i;i=e[i].nxt){
int to=e[i].to;
int w=e[i].w;
if(dist[sg][to]>dist[sg][v]+w){
dist[sg][to]=dist[sg][v]+w;
Q.push({
dist[sg][to],to});
}
}
}
}
bool st[10];
int dfs(int p,int station,int dis){
if(station==5)return dis;
int res=inf;
for(int i=1;i<=5;i++){
if(!st[i]){
st[i]=true;
res=min(res,dfs(i,station+1,dis+dist[p][id[i]]));
st[i]=false;
}
}
return res;
}
int main(int argc, char** argv) {
cin>>n>>m;
id[0]=1;//佳佳家
for(int i=1;i<=5;i++)cin>>id[i];
int u,v,w;
while(m--){
cin>>u>>v>>w;
add(u,v,w);
add(v,u,w);
}
for(int i=0;i<=5;i++)dijikstra(id[i],i);
cout<<dfs(0,0,0); //此时在6个站(0~5)的第几个,到了多少个车站 ,已经花了多少时间
return 0;
}
边栏推荐
- Sorting and searching
- What model is good for the analysis of influencing factors?
- 《opencv学习笔记》-- 霍夫变换
- 如何构建面向海量数据、高实时要求的企业级OLAP数据引擎?
- (translation) timing of website flow chart and user flow chart
- Wechat applet to realize music player (4) (use pubsubjs to realize inter page communication)
- [cloud native] talk about the understanding of the old message middleware ActiveMQ
- I.MX6U-ALPHA开发板(主频和时钟配置实验)
- PathMatchingResourcePatternResolver解析配置文件 资源文件
- PHP 对象转换数组
猜你喜欢

Summary of senior report development experience: understand this and do not make bad reports

Redis如何实现持久化?详细讲解AOF触发机制及其优缺点,带你快速掌握AOF
![[SVN] please execute the 'cleanup' command appears all the time. The solution is that there is no response after cleanup](/img/44/69c434fc9564078e11735881d9bf34.png)
[SVN] please execute the 'cleanup' command appears all the time. The solution is that there is no response after cleanup

Overview of wavelet packet transform methods

Connect external MySQL databases in istio Service Grid

How to build an enterprise level OLAP data engine for massive data and high real-time requirements?

firewall 命令简单操作

Recommendation | DBT skills training manual: baby, you are the reason why you live

How engineers treat open source -- the heartfelt words of an old engineer

Helloworld案例分析
随机推荐
[深入研究4G/5G/6G专题-42]: URLLC-13-《3GPP URLLC相关协议、规范、技术原理深度解读》-7-低延时技术-1-子载波间隔扩展
Where does international crude oil open an account, a formal, safe and secure platform
Introduction to UFS CLK gate
Trust sums two numbers
1. Mx6u-alpha development board (main frequency and clock configuration experiment)
测试用例设计方法之——招式组合,因果判定
匿名函数的作用
Communication protocol and message format between microservices
[cloud native] talk about the understanding of the old message middleware ActiveMQ
Helloworld案例分析
Worked overtime for a week to develop a reporting system. This low code free it reporting artifact is very easy to use
I.MX6U-ALPHA开发板(主频和时钟配置实验)
【读书笔记->数据分析】01 数据分析导论
测试用例设计方法之:入门试招,等价边界初探
`Oi problem solving ` ` leetcode '2040. The k-th minor product of two ordered arrays
当你尝试删除程序中所有烂代码时 | 每日趣闻
Acwing第 61 场周赛【完结】
[cloud native kubernetes] how to use configmap under kubernetes cluster
Web Test Method Encyclopedia
智装时代已来,智哪儿邀您一同羊城论剑,8月4日,光亚展恭候