제출 #126346

#제출 시각아이디문제언어결과실행 시간메모리
126346eriksuenderhauf007 (CEOI14_007)C++11
27 / 100
404 ms49272 KiB
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pil pair<int, long long>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vil vector<pil>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 1e6 + 5;
const double eps = 1e-9;
int n, m, dp[4][MAXN];
vi adj[MAXN];

pii bfs(int src, int x, int y, int p) {
	deque<int> pq;
	mem(dp[p], 0x3f);
	dp[p][src] = 0;
	pq.pb(src);
	while (!pq.empty()) {
		int u = pq.front(); pq.pop_front();
		for (int v: adj[u]) {
			if (dp[p][v] != 1061109567)
				continue;
			dp[p][v] = dp[p][u] + 1;
			pq.pb(v);
		}
	}
	return mp(dp[p][x], dp[p][y]);
}

int main() {
	int s, d, a, b;
	scanf("%d %d %d %d %d %d", &n, &m, &s, &d, &a, &b);
	for (int i = 1; i <= m; i++) {
		int u, v;
		scanf("%d %d", &u, &v);
		adj[u].pb(v);
		adj[v].pb(u);
	}
	pii a1 = bfs(s, a, b, 0);
	pii a2 = bfs(d, a, b, 1);
	pii a3 = bfs(a, a, b, 2);
	pii a4 = bfs(b, a, b, 3);
	//cerr << a1.fi << "/" << a2.fi << " | " << a1.se << "/" << a2.se << "\n";
	int ans = min(a2.fi - a1.fi, a2.se - a1.se);
	if (a2.fi == a2.se && a1.fi == a2.fi) {
		return -1;
		int mi = INF, i1 = 1;
		for (int i = 1; i <= n; i++) {
			if (dp[2][i] != dp[3][i])
				continue;
			if (dp[2][i] + dp[1][i] != a2.fi)
				continue;
			cerr << i << " " << dp[2][i] << " " << dp[1][i] << " " << dp[0][i] << "\n";
			if (mi > dp[2][i])
				i1 = i;
			mi = min(mi, dp[2][i]);
		}
		mi = INF, i1 = 1;
		for (int i = 1; i <= n; i++) {
			if (dp[2][i] != dp[3][i])
				continue;
			if (dp[2][i] + dp[0][i] != a1.fi)
				continue;
			cerr << i << " " << dp[2][i] << " " << dp[1][i] << " " << dp[0][i] << "\n";
			if (mi > dp[2][i])
				i1 = i;
			mi = min(mi, dp[2][i]);
		}
	}
	if (a2.fi == a2.se) ans--;
	if (ans < 0) ans = -1;
	pri(ans);
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

007.cpp: In function 'int main()':
007.cpp:74:17: warning: variable 'i1' set but not used [-Wunused-but-set-variable]
   int mi = INF, i1 = 1;
                 ^~
007.cpp:68:6: warning: variable 'a3' set but not used [-Wunused-but-set-variable]
  pii a3 = bfs(a, a, b, 2);
      ^~
007.cpp:69:6: warning: variable 'a4' set but not used [-Wunused-but-set-variable]
  pii a4 = bfs(b, a, b, 3);
      ^~
007.cpp:59:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d %d %d %d", &n, &m, &s, &d, &a, &b);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
007.cpp:62:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &u, &v);
   ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...