Submission #617804


Source Code Expand

    #include <cstdio>
    #include <vector>
    #include <queue>
    #include <utility>
    using namespace std;
    vector<int> v[26000];
    int nxt[260000][2];
    int len[260000][2];
    int over[260000][2], olen[260000][2];
    int s[260000], w[260000];
    long long d[26000], dt[26000];
    int src, dst, n;
    int f(long long mid) {
    	priority_queue<pair<long long, int> > q;
    	q.push(make_pair(0, src));
    	for (int i = 0; i < n; i++) {
    		dt[i] = 1ll << 61;
    	}
    	dt[src] = 0;
    	while (q.size()) {
    		int pos = q.top().second;
    		long long dis = -q.top().first;
    		q.pop();
    		if (dis != dt[pos]) continue;
    		for (int i = 0; i < v[pos].size(); i++) {
    			int en = v[pos][i];
    			for (int j = 0; j < 2; j++) {
    				if (nxt[en][j] == -1) continue;
    				int npos = nxt[en][j];
    				long long ndis = dis + len[en][j];
    				long long odis = dis + olen[en][j];
    				int opos = over[en][j];
    				if (odis + d[opos] <= mid && dt[npos] > ndis) {
    					dt[npos] = ndis;
    					q.push(make_pair(-ndis, npos));
    				}
    			}
    		}
    	}
    	return dt[dst] <= mid;
    }
    int main() {
    	int m;
    	scanf("%d%d%d%d", &n, &m, &src, &dst);
    	int mc = 0;
    	for (int i = 0; i < m; i++) {
    		int l;
    		scanf("%d", &l);
    		for (int j = 0; j < l; j++) {
    			scanf("%d", &s[j]);
    		}
    		int W = 0;
    		for (int j = 0; j < l - 1; j++) {
    			scanf("%d", &w[j]);
    			W += w[j];
    		}
    		int ww = 0;
    		for (int j = 0; j < l; j++) {
    			int x = s[j];
    			nxt[mc][0] = nxt[mc][1] = -1;
    			if (j > 0) {
    				nxt[mc][0] = s[j-1];
    				len[mc][0] = w[j-1];
    				over[mc][0] = s[0];
    				olen[mc][0] = ww;
    			}
    			if (j < l - 1) {
    				nxt[mc][1] = s[j+1];
    				len[mc][1] = w[j];
    				over[mc][1] = s[l-1];
    				olen[mc][1] = W - ww;
    			}
    			v[x].push_back(mc);
    			mc++;
    			ww += w[j];
    		}
    	}
    	for (int i = 0; i < n; i++) {
    		d[i] = 1ll << 61;
    	}
    	priority_queue<pair<long long, int> > q;
    	q.push(make_pair(0, dst));
    	d[dst] = 0;
    	while (q.size()) {
    		int pos = q.top().second;
    		long long dis = -q.top().first;
    		q.pop();
    		if (dis != d[pos]) continue;
    		for (int i = 0; i < v[pos].size(); i++) {
    			int en = v[pos][i];
    			for (int j = 0; j < 2; j++) {
    				if (nxt[en][j] == -1) continue;
    				int npos = nxt[en][j];
    				long long ndis = dis + len[en][j];
    				if (d[npos] > ndis) {
    					d[npos] = ndis;
    					q.push(make_pair(-ndis, npos));
    				}
    			}
    		}
    	}
    	long long lo = 0, hi = 1ll << 60;
    	while (lo + 1 < hi) {
    		long long mid = (lo + hi) / 2;
    		if (f(mid)) {
    			hi = mid;
    		} else {
    			lo = mid;
    		}
    	}
    	printf("%lld\n", hi);
    	return 0;
    }

Submission Info

Submission Time
Task C - メンテナンス明け
User mkc1370
Language C++ (GCC 4.9.2)
Score 100
Code Size 2968 Byte
Status AC
Exec Time 719 ms
Memory 4908 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:44:43: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
      scanf("%d%d%d%d", &n, &m, &src, &dst);
                                           ^
./Main.cpp:48:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
       scanf("%d", &l);
                      ^
./Main.cpp:50:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
        scanf("%d", &s[j]);
                          ^
./Main.cpp:54:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
        scanf("%d", &w[j]);
                          ^

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 686 ms 4904 KB
large/20_large-01 AC 687 ms 4908 KB
large/20_large-02 AC 719 ms 4896 KB
large/20_large-03 AC 702 ms 4876 KB
large/20_large-04 AC 711 ms 4908 KB
large/31_max_large AC 87 ms 3492 KB
small/00_sample00 AC 27 ms 1564 KB
small/00_sample01 AC 27 ms 1432 KB
small/00_sample02 AC 27 ms 1444 KB
small/10_small-0000 AC 30 ms 1564 KB
small/10_small-0001 AC 29 ms 1448 KB
small/10_small-0002 AC 29 ms 1428 KB
small/10_small-0003 AC 29 ms 1444 KB
small/10_small-0004 AC 29 ms 1372 KB
small/10_small-0005 AC 28 ms 1444 KB
small/10_small-0006 AC 27 ms 1440 KB
small/10_small-0007 AC 29 ms 1440 KB
small/10_small-0008 AC 28 ms 1436 KB
small/10_small-0009 AC 29 ms 1560 KB
small/10_small-0010 AC 28 ms 1560 KB
small/10_small-0011 AC 30 ms 1556 KB
small/10_small-0012 AC 30 ms 1556 KB
small/10_small-0013 AC 32 ms 1436 KB
small/10_small-0014 AC 30 ms 1440 KB
small/10_small-0015 AC 31 ms 1564 KB
small/10_small-0016 AC 30 ms 1440 KB
small/10_small-0017 AC 29 ms 1440 KB
small/10_small-0018 AC 29 ms 1556 KB
small/10_small-0019 AC 29 ms 1444 KB
small/30_max_small AC 29 ms 1552 KB
small/40_simple_0000 AC 28 ms 1564 KB
small/40_simple_0001 AC 27 ms 1316 KB
small/40_simple_0002 AC 27 ms 1436 KB
small/40_simple_0003 AC 27 ms 1380 KB
small/40_simple_0004 AC 26 ms 1452 KB
small/40_simple_0005 AC 27 ms 1444 KB
small/40_simple_0006 AC 27 ms 1444 KB
small/40_simple_0007 AC 27 ms 1436 KB
small/40_simple_0008 AC 28 ms 1560 KB
small/40_simple_0009 AC 28 ms 1448 KB
small/40_simple_0010 AC 27 ms 1564 KB
small/40_simple_0011 AC 25 ms 1324 KB
small/40_simple_0012 AC 26 ms 1320 KB
small/40_simple_0013 AC 29 ms 1356 KB
small/40_simple_0014 AC 27 ms 1312 KB
small/40_simple_0015 AC 27 ms 1336 KB
small/40_simple_0016 AC 27 ms 1320 KB
small/40_simple_0017 AC 27 ms 1436 KB
small/40_simple_0018 AC 27 ms 1444 KB
small/40_simple_0019 AC 28 ms 1320 KB
small/90_dijkstra_killer_00 AC 27 ms 1448 KB
small/90_dijkstra_killer_01 AC 24 ms 1316 KB
small/91_tayama_killer_00 AC 26 ms 1316 KB
small/91_tayama_killer_01 AC 26 ms 1440 KB
small/91_tayama_killer_02 AC 25 ms 1316 KB
small/91_tayama_killer_03 AC 25 ms 1312 KB
small/91_tayama_killer_04 AC 27 ms 1316 KB
small/91_tayama_killer_05 AC 36 ms 1444 KB