답안 #503969

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
503969 2022-01-09T10:22:09 Z Koosha_mv Wild Boar (JOI18_wild_boar) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<(x.F)<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
#define int ll

const int N=4222,S=6,M=4e5+99,inf=1e15;

int n,m,q,L,a[N],X[N],Y[N],cost[N],mark[N],dist[2*N][2*N],seg[M][S][S];
vector<pair<int,int> > g[N];
pair<int,int> adj[N][N][S],b[N][S];

void Get_Ans(){
	int ans=inf;
	f(i,0,S){
		f(j,0,S){
			minm(ans,seg[1][i][j]);
		}
	}
	cout<<(ans==inf ? -1 : ans)<<endl;
}
void dijikastra(int id){
	fill(mark, mark + N, 0);
	fill(dist[id], dist[id] + N, inf);
	queue<int> q;

	dist[id][id] = cost[id];
	q.push(id);
	
	while(q.size()){
		int x = q.front(), u = Y[x], last = X[x];
		//cout<<id<<" "<<x<<" : "<<dist[id][x]<<endl;
		q.pop();
		if(mark[u] == 2) continue ;
		mark[u]++;
		for(auto v : g[u]){
			if(v.F == last) continue ;
			if(dist[id][x] + cost[v.S] < dist[id][v.S]){
				dist[id][v.S] = dist[id][x] + cost[v.S];
				q.push(v.S);
			}
		}
	}
}
void Make(){
	dist[2 * m][2 * m]=inf;
	f(i,0,2*m) dijikastra(i);
	f(u,1,n+1){
		f(v,1,n+1){
			if(u == v) continue ;
			int x = 2 * m, y = 2 * m, s = 0, t = 0, e = 0, p = 0;
			for(auto adju : g[u]){
				for(auto adjv : g[v]){
					adjv.S ^= 1;
					if(dist[adju.S][adjv.S] < dist[x][y]){
						x = adju.S, y = adjv.S;
					}
				}
			}
			adj[u][v][0] = {x, y};
			
			s = 2 * m, t = 2 * m;
			for(auto adju : g[u]){
				for(auto adjv : g[v]){
					adjv.S ^= 1;
					if(adju.S != x && adjv.S == y && dist[adju.S][adjv.S] < dist[s][t]){
						s = adju.S, t = adjv.S;
					}
				}
			}
			adj[u][v][1] = {s, t};		
			
			s = 2 * m, t = 2 * m;
			for(auto adju : g[u]){
				for(auto adjv : g[v]){
					adjv.S ^= 1;
					if(adju.S == x && adjv.S != y && dist[adju.S][adjv.S] < dist[s][t]){
						s = adju.S,t = adjv.S;
					}
				}
			}
			adj[u][v][2] = {s, t};

			
			s = 2 * m, t = 2 * m;
			for(auto adju : g[u]){
				for(auto adjv : g[v]){
					adjv.S ^= 1;
					if(adju.S != x && adjv.S != y && dist[adju.S][adjv.S] < dist[s][t]){
						s = adju.S, t = adjv.S;
					}
				}
			}
			adj[u][v][3] = {s, t};
			
			e = 2 * m, p = 2 * m;
			for(auto adju : g[u]){
				for(auto adjv : g[v]){
					adjv.S ^= 1;
					if(adju.S != x && adjv.S != t && dist[adju.S][adjv.S] < dist[e][p]){
						e = adju.S, p = adjv.S;
					}
				}
			}
			adj[u][v][4] = {e, p};
			
			e = 2 * m, p = 2 * m;
			for(auto adju : g[u]){
				for(auto adjv : g[v]){
					adjv.S ^= 1;
					if(adju.S != s && adjv.S != y && dist[adju.S][adjv.S] < dist[e][p]){
						e = adju.S, p = adjv.S;
					}
				}
			}
			adj[u][v][5] = {e, p};
			
			
			//if((u==2 && v==5) || (u==5 && v==1) || (u==1 && v==5) || (u==5 && v==2)){
			/*if(u==5 && v==1){
			cout<<u<<" -> "<<v<<" : "<<endl;
			for(auto p : adj[u][v]){
				cout<<p.F<<" "<<p.S<<" : "<<dist[p.F][p.S]<<endl;
			}
			cout<<endl;
			}*/
		}
	}	
}
void merge(int id,int id0,int id1,int l,int mid,int r){
	f(i,0,S) f(j,0,S) seg[id][i][j]=inf;
	f(i,0,S){
		f(j,0,S){
			f(k,0,S){
				f(p,0,S){
					if(b[mid-1][j].S/2!=b[mid][k].F/2){
						minm(seg[id][i][p],seg[id0][i][j]+seg[id1][k][p]);
					}
				}
			}
		}
	}
}
void build(int id=1, int l = 0, int r = L - 1){
	if(l + 1 == r){
		f(i,0,S){
			f(j,0,S){
				seg[id][i][j] = (i==j ? dist[b[l][i].F][b[l][i].S] : inf);
			}
		}
		return ;
	}
	int mid = (l + r) >> 1;
	build(id * 2 + 0, l, mid);
	build(id * 2 + 1, mid, r);
	merge(id, id * 2 + 0, id * 2 + 1, l, mid, r);
	/*cout<<id<<" "<<l<<" "<<r<<" : "<<endl;
	f(i,0,S){
		f(j,0,S){
			cout<<b[l][i].F<<" "<<b[r-1][j].S<<" -> "<<seg[id][i][j]<<endl;
		}
	}*/
}
void change(int id,int l,int r,int x){
	if(r<x || x<l) return ;
	if(l+1==r){
		f(i,0,S){
			f(j,0,S){
				seg[id][i][j]=(i==j ? dist[b[l][i].F][b[l][i].S] : inf);
			}
		}
		return ;
	}
	int mid=(l+r)>>1;
	change(id*2+0,l,mid,x);
	change(id*2+1,mid,r,x);
	merge(id, id * 2 + 0, id * 2 + 1, l, mid, r);
}

main(){
	cin>>n>>m>>q>>L;
	f(i,0,2*m){
		if((i&1) == 0){
			cin >> X[i] >> Y[i] >> cost[i];
			X[i+1] = Y[i], Y[i+1] = X[i];
			cost[i+1] = cost[i];
		}
		g[X[i]].pb({Y[i], i});
	}
	Make();
	f(i,0,L){
		cin >> a[i];
		if(i > 0){
			f(j,0,S){
				b[i-1][j] = adj[a[i-1]][a[i]][j];
			}
		}
	}
	build();
	//Get_Ans();
	f(i,0,q){
		int x,val;
		cin>>x>>val; x--;
		a[x]=val;
		if(x>0){
			f(j,0,S){
				b[x-1][j]=adj[a[x-1]][a[x]][j];
			}
		}
		if(x<L-1){
			f(j,0,S){
				b[x][j]=adj[a[x]][a[x+1]][j];
			}
		}
		change(1,0,L-1,x);
		Get_Ans();
	}
}
/*
5 6 0 5
1 2 8
1 3 8
1 4 8
2 5 2
3 4 6
4 5 6

2 5 1 5 2

5 6 0 3
1 2 8
1 3 8
1 4 8
2 5 2
3 4 6
4 5 6

2 5 1


3 3 1 3
1 2 1
2 3 1
1 3 1

1 2 3
*/

Compilation message

wild_boar.cpp:197:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  197 | main(){
      | ^~~~
/tmp/ccaQQpYi.o: in function `Get_Ans()':
wild_boar.cpp:(.text+0xaf): relocation truncated to fit: R_X86_64_PC32 against symbol `std::cout' defined in .bss._ZSt4cout section in /usr/lib/gcc/x86_64-linux-gnu/10/libstdc++.a(globals_io.o)
/tmp/ccaQQpYi.o: in function `dijikastra(long long)':
wild_boar.cpp:(.text+0x519): relocation truncated to fit: R_X86_64_PC32 against symbol `mark' defined in .bss section in /tmp/ccaQQpYi.o
wild_boar.cpp:(.text+0x603): relocation truncated to fit: R_X86_64_PC32 against symbol `cost' defined in .bss section in /tmp/ccaQQpYi.o
wild_boar.cpp:(.text+0x663): relocation truncated to fit: R_X86_64_PC32 against symbol `mark' defined in .bss section in /tmp/ccaQQpYi.o
wild_boar.cpp:(.text+0x69f): relocation truncated to fit: R_X86_64_PC32 against symbol `Y' defined in .bss section in /tmp/ccaQQpYi.o
wild_boar.cpp:(.text+0x6ae): relocation truncated to fit: R_X86_64_PC32 against symbol `X' defined in .bss section in /tmp/ccaQQpYi.o
/tmp/ccaQQpYi.o: in function `Make()':
wild_boar.cpp:(.text+0x886): relocation truncated to fit: R_X86_64_PC32 against symbol `m' defined in .bss section in /tmp/ccaQQpYi.o
wild_boar.cpp:(.text+0x8b4): relocation truncated to fit: R_X86_64_PC32 against symbol `m' defined in .bss section in /tmp/ccaQQpYi.o
wild_boar.cpp:(.text+0x8c8): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccaQQpYi.o
/tmp/ccaQQpYi.o: in function `main':
wild_boar.cpp:(.text.startup+0x9): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccaQQpYi.o
wild_boar.cpp:(.text.startup+0x10): additional relocation overflows omitted from the output
/usr/bin/ld: failed to convert GOTPCREL relocation; relink with --no-relax
collect2: error: ld returned 1 exit status