답안 #77844

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
77844 2018-09-30T18:03:28 Z tmwilliamlin168 Wild Boar (JOI18_wild_boar) C++14
12 / 100
369 ms 27132 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define a array

const int mxN=2e3, mxL=1e5;
const ll INF=1e18;
int n, m, t, l, x[mxL], ai, bi, ci;
vector<a<int, 2>> adj[mxN];
a<ll, 3> d[mxN][mxN][4], st[1<<18][4];
priority_queue<a<ll, 4>, vector<a<ll, 4>>, greater<a<ll, 4>>> pq;

void dij(int s, a<ll, 3> d[mxN][4]) {
	for(int i=0; i<n; ++i)
		for(int j=0; j<4; ++j)
			d[i][j]={INF};
	for(a<int, 2> e : adj[s])
		pq.push({e[0], e[1], e[1], s});
	while(pq.size()) {
		a<ll, 4> u=pq.top();
		pq.pop();
		int i=0, c1=0, c2=0, c3=0;
		while(i<4&&d[u[1]][i][0]<INF) {
			c1+=d[u[1]][i][1]==u[2]&&d[u[1]][i][2]==u[3];
			c2+=d[u[1]][i][1]==u[2];
			c3+=d[u[1]][i][2]==u[3];
			++i;
		}
		if(i>=4||c1||c2>1||c3>1)
			continue;
		d[u[1]][i]={u[0], u[2], u[3]};
		for(a<int, 2> e : adj[u[1]])
			if(e[1]!=u[3])
				pq.push({u[0]+e[0], e[1], u[2], u[1]});
	}
}

void upd(int l1, int i=1, int l2=0, int r2=l-2) {
	if(l2==r2) {
		for(int j=0; j<4; ++j)
			st[i][j]=d[x[l1]][x[l1+1]][j];
		return;
	}
	int m2=(l2+r2)/2;
	if(l1<=m2)
		upd(l1, 2*i, l2, m2);
	else
		upd(l1, 2*i+1, m2+1, r2);
	st[i][0]={0, -1, -1};
	auto b=[&](const int &j) {
		st[i][j]={INF, -1, -1};
		for(int k=0; k<4; ++k)
			for(int l=0; l<4; ++l)
				if(st[2*i][k][1]!=st[i][j&1?0:3][1]&&st[2*i+1][l][2]!=st[i][j&2?0:3][2]&&st[2*i][k][2]!=st[2*i+1][l][1])
					st[i][j]=min(a<ll, 3>{st[2*i][k][0]+st[2*i+1][l][0], st[2*i][k][1], st[2*i+1][l][2]}, st[i][j]);
	};
	b(3);
	for(int j=0; j<3; ++j)
		b(j);
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m >> t >> l;
	while(m--) {
		cin >> ai >> bi >> ci, --ai, --bi;
		adj[ai].push_back({ci, bi});
		adj[bi].push_back({ci, ai});
	}
	for(int i=0; i<n; ++i)
		dij(i, d[i]);
	for(int i=0; i<l; ++i) {
		cin >> x[i], --x[i];
		if(i)
			upd(i-1);
	}
	while(t--) {
		int pk, qk;
		cin >> pk >> qk, --pk, --qk;
		x[pk]=qk;
		if(pk)
			upd(pk-1);
		if(pk<l-1)
			upd(pk);
		ll ans=min({st[1][0][0], st[1][1][0], st[1][2][0], st[1][3][0]});
		cout << (ans>=INF?-1:ans) << "\n";
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 628 KB Output is correct
3 Correct 2 ms 628 KB Output is correct
4 Correct 2 ms 640 KB Output is correct
5 Correct 2 ms 692 KB Output is correct
6 Correct 2 ms 716 KB Output is correct
7 Correct 2 ms 716 KB Output is correct
8 Correct 2 ms 716 KB Output is correct
9 Correct 2 ms 716 KB Output is correct
10 Correct 2 ms 716 KB Output is correct
11 Correct 2 ms 716 KB Output is correct
12 Correct 2 ms 716 KB Output is correct
13 Correct 2 ms 716 KB Output is correct
14 Correct 2 ms 716 KB Output is correct
15 Correct 2 ms 716 KB Output is correct
16 Correct 2 ms 716 KB Output is correct
17 Correct 2 ms 720 KB Output is correct
18 Correct 2 ms 720 KB Output is correct
19 Correct 2 ms 736 KB Output is correct
20 Correct 2 ms 736 KB Output is correct
21 Correct 2 ms 736 KB Output is correct
22 Correct 2 ms 736 KB Output is correct
23 Correct 2 ms 736 KB Output is correct
24 Correct 2 ms 736 KB Output is correct
25 Correct 2 ms 736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 628 KB Output is correct
3 Correct 2 ms 628 KB Output is correct
4 Correct 2 ms 640 KB Output is correct
5 Correct 2 ms 692 KB Output is correct
6 Correct 2 ms 716 KB Output is correct
7 Correct 2 ms 716 KB Output is correct
8 Correct 2 ms 716 KB Output is correct
9 Correct 2 ms 716 KB Output is correct
10 Correct 2 ms 716 KB Output is correct
11 Correct 2 ms 716 KB Output is correct
12 Correct 2 ms 716 KB Output is correct
13 Correct 2 ms 716 KB Output is correct
14 Correct 2 ms 716 KB Output is correct
15 Correct 2 ms 716 KB Output is correct
16 Correct 2 ms 716 KB Output is correct
17 Correct 2 ms 720 KB Output is correct
18 Correct 2 ms 720 KB Output is correct
19 Correct 2 ms 736 KB Output is correct
20 Correct 2 ms 736 KB Output is correct
21 Correct 2 ms 736 KB Output is correct
22 Correct 2 ms 736 KB Output is correct
23 Correct 2 ms 736 KB Output is correct
24 Correct 2 ms 736 KB Output is correct
25 Correct 2 ms 736 KB Output is correct
26 Correct 3 ms 748 KB Output is correct
27 Correct 253 ms 26976 KB Output is correct
28 Correct 260 ms 27096 KB Output is correct
29 Incorrect 369 ms 27132 KB Output isn't correct
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 628 KB Output is correct
3 Correct 2 ms 628 KB Output is correct
4 Correct 2 ms 640 KB Output is correct
5 Correct 2 ms 692 KB Output is correct
6 Correct 2 ms 716 KB Output is correct
7 Correct 2 ms 716 KB Output is correct
8 Correct 2 ms 716 KB Output is correct
9 Correct 2 ms 716 KB Output is correct
10 Correct 2 ms 716 KB Output is correct
11 Correct 2 ms 716 KB Output is correct
12 Correct 2 ms 716 KB Output is correct
13 Correct 2 ms 716 KB Output is correct
14 Correct 2 ms 716 KB Output is correct
15 Correct 2 ms 716 KB Output is correct
16 Correct 2 ms 716 KB Output is correct
17 Correct 2 ms 720 KB Output is correct
18 Correct 2 ms 720 KB Output is correct
19 Correct 2 ms 736 KB Output is correct
20 Correct 2 ms 736 KB Output is correct
21 Correct 2 ms 736 KB Output is correct
22 Correct 2 ms 736 KB Output is correct
23 Correct 2 ms 736 KB Output is correct
24 Correct 2 ms 736 KB Output is correct
25 Correct 2 ms 736 KB Output is correct
26 Correct 3 ms 748 KB Output is correct
27 Correct 253 ms 26976 KB Output is correct
28 Correct 260 ms 27096 KB Output is correct
29 Incorrect 369 ms 27132 KB Output isn't correct
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 628 KB Output is correct
3 Correct 2 ms 628 KB Output is correct
4 Correct 2 ms 640 KB Output is correct
5 Correct 2 ms 692 KB Output is correct
6 Correct 2 ms 716 KB Output is correct
7 Correct 2 ms 716 KB Output is correct
8 Correct 2 ms 716 KB Output is correct
9 Correct 2 ms 716 KB Output is correct
10 Correct 2 ms 716 KB Output is correct
11 Correct 2 ms 716 KB Output is correct
12 Correct 2 ms 716 KB Output is correct
13 Correct 2 ms 716 KB Output is correct
14 Correct 2 ms 716 KB Output is correct
15 Correct 2 ms 716 KB Output is correct
16 Correct 2 ms 716 KB Output is correct
17 Correct 2 ms 720 KB Output is correct
18 Correct 2 ms 720 KB Output is correct
19 Correct 2 ms 736 KB Output is correct
20 Correct 2 ms 736 KB Output is correct
21 Correct 2 ms 736 KB Output is correct
22 Correct 2 ms 736 KB Output is correct
23 Correct 2 ms 736 KB Output is correct
24 Correct 2 ms 736 KB Output is correct
25 Correct 2 ms 736 KB Output is correct
26 Correct 3 ms 748 KB Output is correct
27 Correct 253 ms 26976 KB Output is correct
28 Correct 260 ms 27096 KB Output is correct
29 Incorrect 369 ms 27132 KB Output isn't correct
30 Halted 0 ms 0 KB -