当前位置:网站首页>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;
}
边栏推荐
- Luoda development - audio stream processing - AAC / loopbacktest as an example
- 《opencv学习笔记》-- 霍夫变换
- PHP < => spacecraft operator (combined comparator)
- Firewall command simple operation
- The era of smart clothes has come. Zhinar invites you to discuss swords in Yangcheng. Guangya Exhibition is waiting for you on August 4
- 软模拟光栅化渲染器
- Connect external MySQL databases in istio Service Grid
- Chapter 18: explore the wonders of the mean in the 2-bit a~b system, specify the 3x+1 conversion process of integers, specify an interval to verify the angular Valley conjecture, explore the number of
- laravel8 实现接口鉴权封装使用JWT
- Seat / safety configuration upgrade is the administrative experience of the new Volvo S90 in place
猜你喜欢

如何构建面向海量数据、高实时要求的企业级OLAP数据引擎?

When you try to delete all bad code in the program | daily anecdotes

What are the duplicate check rules for English papers?

Introduction to UFS CLK gate

Mantium 如何在 Amazon SageMaker 上使用 DeepSpeed 实现低延迟 GPT-J 推理

I.MX6U-ALPHA开发板(主频和时钟配置实验)
![[Reading Notes - > data analysis] 01 introduction to data analysis](/img/50/622878bf649e77d5a4fa9732fa6f92.png)
[Reading Notes - > data analysis] 01 introduction to data analysis
![[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

Sentinel fusing and current limiting

Wechat applet to realize music player (4) (use pubsubjs to realize inter page communication)
随机推荐
Opencv learning notes -- Hough transform
2021 CIKM |GF-VAE: A Flow-based Variational Autoencoder for Molecule Generation
华为再发“天才少年”全球召集令,有人曾放弃360万年薪加入
如何构建面向海量数据、高实时要求的企业级OLAP数据引擎?
Go Plus Security:一款Build Web3不可或缺的安全生态基础设施
Use of rule engine drools
Sentinel fusing and current limiting
红星美凯龙高负债之下,盯上新能源了?
Lua and go mixed call debugging records support cross platform (implemented through C and luajit)
I.MX6U-ALPHA开发板(主频和时钟配置实验)
Web测试方法大全
Where does international crude oil open an account, a formal, safe and secure platform
Recommendation Book Educational Psychology: a book for tomorrow's teachers~
Inventory the concept, classification and characteristics of cloud computing
How to build an enterprise level OLAP data engine for massive data and high real-time requirements?
ZK snark: about private key, ring signature, zkksp
`Oi problem solving ` ` leetcode '2040. The k-th minor product of two ordered arrays
When you try to delete all bad code in the program | daily anecdotes
Apple removed the last Intel chip from its products
laravel8 实现接口鉴权封装使用JWT