Submission #617166


Source Code Expand

#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
using namespace std;

typedef long long Int;
typedef pair<Int, Int> P;
typedef pair<P, Int> T;
#define INF (1LL << 60)
vector<P> edge[32400];
vector<T> sedge[32400];
vector<Int> w[324000];
vector<Int> s[324000];

Int n, m, src, dst;
Int l[32400];
Int tmp;
Int dists[324000], distd[32400];
Int up[324000], down[324000];                      

void dijkstra(Int s, Int *dist){
	fill(dist, dist + 32400, INF);	
	priority_queue<P, vector<P>, greater<P> > pq;
	
	dist[s] = 0;
	pq.push(P(0, s));
	
	while(!pq.empty()){
		P tmp = pq.top();pq.pop();
		Int d = tmp.first;
		Int from = tmp.second;
		if(dist[from] < d)continue;
		for(Int i = 0;i < edge[from].size();i++){
			Int to = edge[from][i].first;
			Int dis = edge[from][i].second;
			if(dist[to] > dist[from] + dis){
				dist[to] = dist[from] + dis;
				pq.push(P(dist[to], to));
			}
		}
	}
}



void maxdijkstra(Int s, Int *dist){
	fill(dist, dist + 32400, INF);
	
	priority_queue<P, vector<P>, greater<P> > pq;
	
	dist[s] = 0;
	pq.push(P(0, s));
	
	while(!pq.empty()){
		P tmp = pq.top();pq.pop();
		Int d = tmp.first;
		Int from = tmp.second;
		if(dist[from] < d)continue;
		for(Int i = 0;i < sedge[from].size();i++){
			Int to = sedge[from][i].first.first;
			Int dis = sedge[from][i].first.second;
			Int ww = sedge[from][i].second;
			if(dist[to] > max(dist[from] + ww, dis)){
				dist[to] = max(dist[from] + ww, dis);
				pq.push(P(dist[to], to));
			}
		}
	}
}

int main(){
	cin >> n >> m >> src >> dst;
	for(Int i = 0;i < m;i++){
		cin >> l[i];
		for(Int j = 0;j < l[i];j++){
			cin >> tmp;
			s[i].push_back(tmp);
		}
		for(Int j = 0;j < l[i] - 1;j++){
			cin >> tmp;
			w[i].push_back(tmp);
			edge[s[i][j]].push_back(P(s[i][j+1], tmp));
			edge[s[i][j+1]].push_back(P(s[i][j], tmp));
		}
	}
	                     
	dijkstra(src, dists);
	dijkstra(dst, distd);
	
//	for(int i = 0;i < n;i++)cout << dists[i] << " " << distd[i] << endl;
	
	for(Int i = 0;i < m;i++){
		up[0] = down[l[i]-1] = 0;
		for(Int j = 0;j < l[i]-1;j++){
			up[j+1] = w[i][j];
			down[j] = w[i][j];
		}
		Int upper = s[i][l[i]-1];
		Int lower = s[i][0];
		for(Int j = 1;j < l[i];j++)up[j] += up[j-1];//, cout << j << " " << up[j] << endl;
		for(Int j = l[i]-2;j >= 0;j--)down[j] += down[j+1];//, cout << j << " " << down[j] << endl;
		for(Int j = 0;j < l[i]-1;j++){
			Int a = s[i][j], b = s[i][j+1];
//			cout << a << " " << b << " " << down[j] << " " << distd[upper] << endl;
//			cout << b << " " << a << " " << up[j+1] << " " << distd[lower] << endl;
			sedge[b].push_back(T(P(a, down[j] + distd[upper]), w[i][j]));
			sedge[a].push_back(T(P(b, up[j+1] + distd[lower]), w[i][j]));
		}
	}
	
	maxdijkstra(dst, dists);
	
	cout << dists[src] << endl;	
	return 0;
}

Submission Info

Submission Time
Task C - メンテナンス明け
User catupper
Language C++ (GCC 4.9.2)
Score 100
Code Size 2899 Byte
Status AC
Exec Time 177 ms
Memory 25088 KB

Judge Result

Set Name Subtask1 Subtask2
Score / Max Score 50 / 50 50 / 50
Status
AC × 52
AC × 6
Set Name Test Cases
Subtask1 small/00_sample00, small/00_sample01, small/00_sample02, small/10_small-0000, small/10_small-0001, small/10_small-0002, small/10_small-0003, small/10_small-0004, small/10_small-0005, small/10_small-0006, small/10_small-0007, small/10_small-0008, small/10_small-0009, small/10_small-0010, small/10_small-0011, small/10_small-0012, small/10_small-0013, small/10_small-0014, small/10_small-0015, small/10_small-0016, small/10_small-0017, small/10_small-0018, small/10_small-0019, small/30_max_small, small/40_simple_0000, small/40_simple_0001, small/40_simple_0002, small/40_simple_0003, small/40_simple_0004, small/40_simple_0005, small/40_simple_0006, small/40_simple_0007, small/40_simple_0008, small/40_simple_0009, small/40_simple_0010, small/40_simple_0011, small/40_simple_0012, small/40_simple_0013, small/40_simple_0014, small/40_simple_0015, small/40_simple_0016, small/40_simple_0017, small/40_simple_0018, small/40_simple_0019, small/90_dijkstra_killer_00, small/90_dijkstra_killer_01, small/91_tayama_killer_00, small/91_tayama_killer_01, small/91_tayama_killer_02, small/91_tayama_killer_03, small/91_tayama_killer_04, small/91_tayama_killer_05
Subtask2 large/20_large-00, large/20_large-01, large/20_large-02, large/20_large-03, large/20_large-04, large/31_max_large
Case Name Status Exec Time Memory
large/20_large-00 AC 177 ms 25076 KB
large/20_large-01 AC 177 ms 25088 KB
large/20_large-02 AC 173 ms 25088 KB
large/20_large-03 AC 173 ms 24836 KB
large/20_large-04 AC 177 ms 24960 KB
large/31_max_large AC 96 ms 21664 KB
small/00_sample00 AC 58 ms 18088 KB
small/00_sample01 AC 59 ms 18084 KB
small/00_sample02 AC 56 ms 18080 KB
small/10_small-0000 AC 57 ms 18084 KB
small/10_small-0001 AC 60 ms 18088 KB
small/10_small-0002 AC 56 ms 18080 KB
small/10_small-0003 AC 58 ms 18084 KB
small/10_small-0004 AC 59 ms 18080 KB
small/10_small-0005 AC 59 ms 18080 KB
small/10_small-0006 AC 72 ms 18216 KB
small/10_small-0007 AC 59 ms 18080 KB
small/10_small-0008 AC 57 ms 18204 KB
small/10_small-0009 AC 62 ms 18072 KB
small/10_small-0010 AC 58 ms 18076 KB
small/10_small-0011 AC 59 ms 18196 KB
small/10_small-0012 AC 56 ms 18080 KB
small/10_small-0013 AC 58 ms 18088 KB
small/10_small-0014 AC 58 ms 18084 KB
small/10_small-0015 AC 58 ms 18204 KB
small/10_small-0016 AC 57 ms 18084 KB
small/10_small-0017 AC 57 ms 18076 KB
small/10_small-0018 AC 58 ms 18084 KB
small/10_small-0019 AC 57 ms 18084 KB
small/30_max_small AC 56 ms 18084 KB
small/40_simple_0000 AC 58 ms 18080 KB
small/40_simple_0001 AC 58 ms 18084 KB
small/40_simple_0002 AC 59 ms 18084 KB
small/40_simple_0003 AC 58 ms 18080 KB
small/40_simple_0004 AC 58 ms 18084 KB
small/40_simple_0005 AC 57 ms 18080 KB
small/40_simple_0006 AC 64 ms 18080 KB
small/40_simple_0007 AC 63 ms 18084 KB
small/40_simple_0008 AC 62 ms 18088 KB
small/40_simple_0009 AC 61 ms 18084 KB
small/40_simple_0010 AC 62 ms 18084 KB
small/40_simple_0011 AC 63 ms 18080 KB
small/40_simple_0012 AC 62 ms 18084 KB
small/40_simple_0013 AC 62 ms 18076 KB
small/40_simple_0014 AC 63 ms 18072 KB
small/40_simple_0015 AC 63 ms 18080 KB
small/40_simple_0016 AC 64 ms 18084 KB
small/40_simple_0017 AC 64 ms 18208 KB
small/40_simple_0018 AC 64 ms 18072 KB
small/40_simple_0019 AC 64 ms 18084 KB
small/90_dijkstra_killer_00 AC 64 ms 18068 KB
small/90_dijkstra_killer_01 AC 61 ms 18076 KB
small/91_tayama_killer_00 AC 63 ms 18084 KB
small/91_tayama_killer_01 AC 62 ms 18092 KB
small/91_tayama_killer_02 AC 63 ms 18080 KB
small/91_tayama_killer_03 AC 63 ms 18088 KB
small/91_tayama_killer_04 AC 77 ms 18076 KB
small/91_tayama_killer_05 AC 63 ms 18080 KB