Moderator: Board moderators
Cut after AC. Small OO caused WA
p.cc:12: error: ‘std::list<one, std::allocator<one> > link [20002]’ redeclared as different kind of symbol
/usr/include/unistd.h:757: error: previous declaration of ‘int link(const char*, const char*)’
p.cc: In function ‘void Free()’:
p.cc:33: error: pointer to a function used in arithmetic
p.cc:33: error: request for member ‘clear’ in ‘*(((int (*)(const char*, const char*)throw ())((unsigned int)m)) + link)’, which is of non-class type ‘int ()(const char*, const char*)throw ()’
p.cc: In function ‘int Dijkstra(int, int)’:
p.cc:52: error: pointer to a function used in arithmetic
p.cc:52: error: request for member ‘begin’ in ‘*(((int (*)(const char*, const char*)throw ())((unsigned int)s.two::node)) + link)’, which is of non-class type ‘int ()(const char*, const char*)throw ()’
p.cc:52: error: pointer to a function used in arithmetic
p.cc:52: error: request for member ‘end’ in ‘*(((int (*)(const char*, const char*)throw ())((unsigned int)s.two::node)) + link)’, which is of non-class type ‘int ()(const char*, const char*)throw ()’
p.cc: In function ‘int main()’:
p.cc:81: error: pointer to a function used in arithmetic
p.cc:81: error: request for member ‘push_back’ in ‘*(((int (*)(const char*, const char*)throw ())((unsigned int)v)) + link)’, which is of non-class type ‘int ()(const char*, const char*)throw ()’
p.cc:83: error: pointer to a function used in arithmetic
p.cc:83: error: request for member ‘push_back’ in ‘*(((int (*)(const char*, const char*)throw ())((unsigned int)u)) + link)’, which is of non-class type ‘int ()(const char*, const char*)throw ()’
#include <cstdio>
#include <queue>
#include <climits>
#include <vector>
using namespace std;
//const int MAX_V = 2000;
//const int MAX_ARESTAS = 5001;
//const int INF = INT_MAX;
const int MAX_V = 20001;
const int MAX_EDGES = 50001;
const int INF = INT_MAX;
typedef struct grafo
{
int v, w;
}GRAPH;
int N, n, m, S, T;
int degree[MAX_V], dist[MAX_V], f[MAX_V];//f: father
vector< vector<GRAPH> > g(MAX_V, vector<GRAPH>(MAX_EDGES));
//GRAFO g[MAX_V][MAX_ARESTAS];
void Inic()
{
for(int i=0; i<n; i++){
degree[i] = 0;
}
}
pair<int, int> MP(int v, int w)
{
pair<int, int> P;
P.first = v; P.second = w;
return P;
}
void dijkstra(int o, int dest)//o: source
{
priority_queue< pair<int, int> > heap;//w, vertice
int s, t, w;
for(int i=0; i<n; i++){
dist[i] = INF;
f[i] = i;
}
heap.push( MP(dist[o]=0, o) );
while(!heap.empty()){
s = heap.top().second;
heap.pop();
for(int i=1; i<=degree[s]; i++){
t = g[s][i].v;
w = g[s][i].w;
if(dist[s] + w < dist[t]){
dist[t] = dist[s] + w;
f[t] = s;
heap.push( MP(-dist[t], t) );
}
}
if(s == dest) return;//Optimization
}
}
int main()
{
scanf("%d", &N);
for(int test=1; test<=N; test++){
scanf("%d %d %d %d", &n, &m, &S, &T);
Inic();
for(int M=1; M<=m; M++){
int s, d, w;
scanf("%d %d %d", &s, &d, &w);
degree[s]++; degree[d]++;
g[s][ degree[s] ].v = d;
g[s][ degree[s] ].w = w;
g[d][ degree[d] ].v = s;
g[d][ degree[d] ].w = w;
}
dijkstra(S, T);
printf("Case %d#: ", test);
if(dist[T] == INF) printf("unreachable\n");
else printf("%d\n", dist[T]);
}
}
#include<iostream>
#include<vector>
#define inf 1000000000
#define SIZE1 20000
#define SIZE2 50000
using namespace std;
typedef vector<int>graph;
long Q[SIZE1+9],d[SIZE1+9];
graph G[SIZE2*2+9],W[SIZE2*2+9];
//min_heapify with respect to d[]
long min_heapify(long i,long n)
{
long temp,minimum,l,r;
l=2*i;
r=2*i+1;
if(l<=n && d[Q[l]]<d[Q[i]])
minimum=l;
else
minimum=i;
if(r<=n && d[Q[r]]<d[Q[minimum]])
minimum=r;
if(minimum!=i)
{
temp=Q[i];
Q[i]=Q[minimum];
Q[minimum]=temp;
min_heapify(minimum,n);
}
return 0;
}
long build_min_heap(long n)
{
long i;
for(i=n/2;i>0;i--)
{
min_heapify(i,n);
}
return 0;
}
long extract_min_Q(long n)
{
build_min_heap(n);
long min;
min=Q[1];
Q[1]=Q[n];
return min;
}
int main()
{
long i,j,n,m,u,v,w,source,dest,t;
scanf("%ld",&t);
for(j=1;j<=t;j++)
{
scanf("%ld%ld%ld%ld",&n,&m,&source,&dest);
for(i=1;i<=n;i++)
{
G[i].clear();
W[i].clear();
}
for(i=1;i<=m;i++)
{
scanf("%ld%ld%ld",&u,&v,&w);
G[u+1].push_back(v+1);
G[v+1].push_back(u+1);
W[u+1].push_back(w);
W[v+1].push_back(w);
}
for(i=1;i<=n;i++)
{
d[i]=inf;
Q[i]=i;
}
d[source+1]=0;
while(n>0)
{
u=extract_min_Q(n);
n--;
for(v=0;v<G[u].size();v++)
{
if((d[u]+W[u][v])<d[G[u][v]])
{
d[G[u][v]]=d[u]+W[u][v];
}
}
}
if(d[dest+1]==inf)
printf("Case #%ld: unreachable\n",j);
else
printf("Case #%ld: %ld\n",j,d[dest+1]);
}
return 0;
}
Users browsing this forum: No registered users and 1 guest