Submission #102569


Source Code Expand

#include <cstdio>
#include <vector>
#include <queue>
#include <iostream>

using namespace std;

struct edge {
	int src, dst;
	edge(int s, int d) : src(s), dst(d) { }
};
typedef vector<edge> edges;
typedef vector<edges> graph;

int D[100050], E[100050];
int Dc[100050], Ec[100050];

int main()
{
	int N, M, s, t;

	scanf("%d%d%d%d", &N, &M, &s, &t);
	--s; --t;

	graph G(N);
	for (int i = 0; i < M; ++i) {
		int x, y;
		scanf("%d%d", &x, &y);
		--x; --y;
		G[x].push_back(edge(x, y));
		G[y].push_back(edge(y, x));
	}

	for (int i = 0; i < N; ++i) D[i] = E[i] = 1001001001;

	queue<int> Q;
	Q.push(s); D[s] = 0;
	while (!Q.empty()) {
		int u = Q.front(); Q.pop();
		for (int i = 0; i < G[u].size(); ++i) {
			int v = G[u][i].dst;
			if (D[v] > D[u] + 1) {
				D[v] = D[u] + 1;
				Q.push(v);
			}
		}
	}

	Q = queue<int>();
	Q.push(t); E[t] = 0;
	while (!Q.empty()) {
		int u = Q.front(); Q.pop();
		for (int i = 0; i < G[u].size(); ++i) {
			int v = G[u][i].dst;
			if (E[v] > E[u] + 1) {
				E[v] = E[u] + 1;
				Q.push(v);
			}
		}
	}

	long long res = 0;
	for (int i = 0; i < N; ++i) {
		if (D[i] <= N) Dc[D[i]]++;
		if (E[i] <= N) Ec[E[i]]++;
	}

	for (int d = 0; d <= N; ++d) {
		int e = D[t] - d - 2;
		if (e >= 0 && e <= N && Dc[d] && Ec[e]) {
			// cerr << d << ' ' << e << ' ' << Dc[d] << ' ' << Ec[e] << endl;
			res += (long long)Dc[d] * Ec[e];
		}
	}

	printf("%lld\n", res);
	
	return 0;
}

Submission Info

Submission Time
Task B - Minus One
User Operasan
Language C++ (GCC 4.4.7)
Score 100
Code Size 1484 Byte
Status AC
Exec Time 156 ms
Memory 8736 KiB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result
./Main.cpp:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 73
Set Name Test Cases
All 00-sample1.txt, 00-sample2.txt, 00-sample4.txt, 50-random10.txt, 50-random11.txt, 50-random12.txt, 50-random13.txt, 50-random14.txt, 50-random15.txt, 50-random16.txt, 50-random17.txt, 50-random18.txt, 50-random19.txt, 50-random20.txt, 50-random21.txt, 50-random22.txt, 50-random23.txt, 50-random24.txt, 50-random25.txt, 50-random26.txt, 50-random27.txt, 50-random28.txt, 50-random29.txt, 50-random30.txt, 50-random31.txt, 50-random32.txt, 50-random33.txt, 50-random34.txt, 50-random35.txt, 50-random36.txt, 50-random37.txt, 50-random38.txt, 50-random39.txt, 50-random40.txt, 50-random41.txt, 50-random42.txt, 50-random43.txt, 50-random44.txt, 50-random45.txt, 50-random46.txt, 50-random47.txt, 50-random48.txt, 50-random49.txt, 50-random50.txt, 50-random51.txt, 50-random52.txt, 50-random53.txt, 50-random54.txt, 50-random55.txt, 50-random56.txt, 50-random57.txt, 50-random58.txt, 50-random59.txt, 50-random60.txt, 50-random61.txt, 50-random62.txt, 50-random63.txt, 50-random64.txt, 50-random65.txt, 50-random66.txt, 50-random67.txt, 50-random68.txt, 50-random69.txt, intoverflow00.txt, intoverflow01.txt, intoverflow02.txt, intoverflow03.txt, intoverflow04.txt, intoverflow05.txt, intoverflow06.txt, intoverflow07.txt, intoverflow08.txt, intoverflow09.txt
Case Name Status Exec Time Memory
00-sample1.txt AC 21 ms 912 KiB
00-sample2.txt AC 21 ms 916 KiB
00-sample4.txt AC 22 ms 808 KiB
50-random10.txt AC 21 ms 848 KiB
50-random11.txt AC 22 ms 812 KiB
50-random12.txt AC 22 ms 912 KiB
50-random13.txt AC 20 ms 912 KiB
50-random14.txt AC 22 ms 924 KiB
50-random15.txt AC 24 ms 796 KiB
50-random16.txt AC 21 ms 872 KiB
50-random17.txt AC 22 ms 808 KiB
50-random18.txt AC 22 ms 924 KiB
50-random19.txt AC 22 ms 808 KiB
50-random20.txt AC 22 ms 924 KiB
50-random21.txt AC 21 ms 916 KiB
50-random22.txt AC 22 ms 804 KiB
50-random23.txt AC 22 ms 920 KiB
50-random24.txt AC 21 ms 920 KiB
50-random25.txt AC 22 ms 848 KiB
50-random26.txt AC 21 ms 916 KiB
50-random27.txt AC 20 ms 912 KiB
50-random28.txt AC 22 ms 796 KiB
50-random29.txt AC 22 ms 920 KiB
50-random30.txt AC 22 ms 924 KiB
50-random31.txt AC 21 ms 920 KiB
50-random32.txt AC 22 ms 924 KiB
50-random33.txt AC 21 ms 920 KiB
50-random34.txt AC 21 ms 920 KiB
50-random35.txt AC 23 ms 920 KiB
50-random36.txt AC 21 ms 920 KiB
50-random37.txt AC 20 ms 920 KiB
50-random38.txt AC 23 ms 924 KiB
50-random39.txt AC 21 ms 916 KiB
50-random40.txt AC 22 ms 1044 KiB
50-random41.txt AC 21 ms 924 KiB
50-random42.txt AC 21 ms 920 KiB
50-random43.txt AC 22 ms 920 KiB
50-random44.txt AC 22 ms 920 KiB
50-random45.txt AC 23 ms 792 KiB
50-random46.txt AC 21 ms 832 KiB
50-random47.txt AC 22 ms 904 KiB
50-random48.txt AC 21 ms 924 KiB
50-random49.txt AC 22 ms 920 KiB
50-random50.txt AC 25 ms 1308 KiB
50-random51.txt AC 31 ms 1580 KiB
50-random52.txt AC 24 ms 936 KiB
50-random53.txt AC 29 ms 1572 KiB
50-random54.txt AC 31 ms 1572 KiB
50-random55.txt AC 32 ms 1708 KiB
50-random56.txt AC 22 ms 804 KiB
50-random57.txt AC 26 ms 1328 KiB
50-random58.txt AC 24 ms 1308 KiB
50-random59.txt AC 25 ms 1064 KiB
50-random60.txt AC 99 ms 5928 KiB
50-random61.txt AC 86 ms 5540 KiB
50-random62.txt AC 145 ms 7976 KiB
50-random63.txt AC 85 ms 5536 KiB
50-random64.txt AC 91 ms 6188 KiB
50-random65.txt AC 43 ms 2856 KiB
50-random66.txt AC 41 ms 2976 KiB
50-random67.txt AC 34 ms 2968 KiB
50-random68.txt AC 27 ms 1324 KiB
50-random69.txt AC 25 ms 2216 KiB
intoverflow00.txt AC 141 ms 8732 KiB
intoverflow01.txt AC 145 ms 8728 KiB
intoverflow02.txt AC 139 ms 8724 KiB
intoverflow03.txt AC 150 ms 8736 KiB
intoverflow04.txt AC 140 ms 8728 KiB
intoverflow05.txt AC 156 ms 8724 KiB
intoverflow06.txt AC 140 ms 8728 KiB
intoverflow07.txt AC 141 ms 8724 KiB
intoverflow08.txt AC 138 ms 8728 KiB
intoverflow09.txt AC 138 ms 8732 KiB