Submission #110516

#TimeUsernameProblemLanguageResultExecution timeMemory
110516ckodser007 (CEOI14_007)C++14
0 / 100
537 ms140876 KiB
#include<bits/stdc++.h> #define pb push_back using namespace std; const int N = 1000006; int n, m, a, b, s1, s2, D[2][N], F[N], P[N]; vector < int > vec[N], Adj[N]; inline void BFS(int st, int w, int tp = 0) { queue < int > qu; qu.push(st); D[w][st] = 0; while (qu.size()) { int v = qu.front(); qu.pop(); if (tp) vec[D[w][v]].pb(v); for (int &u : Adj[v]) if (D[w][u] == -1) D[w][u] = D[w][v] + 1, qu.push(u); } } inline bool Check(int s, int t) { if (D[0][t] < D[0][s] || D[1][t] < D[1][s]) return 0; if (D[0][s] < D[0][t] || D[1][s] < D[1][t]) return 1; return (F[s] <= F[t]); } inline bool CMP(int i, int j) { return (D[0][i] <= D[0][j]); } int main() { scanf("%d%d%d%d%d%d", &n, &m, &s1, &s2, &a, &b); for (int i = 0; i < m; i++) { int v, u; scanf("%d%d", &v, &u); Adj[v].pb(u); Adj[u].pb(v); } memset(D, -1, sizeof(D)); BFS(s2, 0, 1); memset(D, -1, sizeof(D)); BFS(a, 0); BFS(b, 1); memset(F, 63, sizeof(F)); for (int i = 1; i <= n; i++) P[i] = i; sort(P + 1, P + n + 1, CMP); for (int i = 1; i <= n; i++) { int v = P[i]; if (D[0][v] == D[1][v]) { F[v] = D[0][v]; for (int u : Adj[v]) if (D[0][v] == D[0][u] + 1 && D[1][v] == D[1][u] + 1) F[v] = min(F[v], F[u]); } } for (int i = 0; i <= n; i ++) for (int v : vec[i]) if (!Check(s1, v)) return !printf("%d\n", i - 1); return 0; }

Compilation message (stderr)

007.cpp: In function 'int main()':
007.cpp:35: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, &s1, &s2, &a, &b);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
007.cpp:39:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &v, &u);
   ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...