Submission #91093

#TimeUsernameProblemLanguageResultExecution timeMemory
91093YottaByteShymbulak (IZhO14_shymbulak)C++14
0 / 100
19 ms844 KiB
#include <string.h> #include <stdio.h> #include <vector> #include <queue> using namespace std; const int N = 5001; #define pb emplace_back #define fr first #define sc second #define mk make_pair int n, d[N], u[N]; int ans, mx, root; vector < int > g[N], v; void dij(int x, int curd = 1) { priority_queue < pair < int, int > > pq; pq.push( mk( -curd, x ) ); d[x] = curd; while(!pq.empty()) { x = pq.top().sc; curd = -pq.top().fr; pq.pop(); if(curd > d[x]) continue; for(int to : g[x]) { if(d[to] == 0 || d[to] > curd + 1) { d[to] = curd + 1; pq.push( mk( -d[to], to ) ); } } } } void dfs(int v, int dist = 0, int p = 0) { u[v] = 1; if(dist == mx) { //printf("%d\n", v); ans++; return; } for(int to : g[v]) if(d[to] - 1 == dist + 1) dfs(to, dist + 1, v); } main() { scanf("%d", &n); for(int i = 1; i <= n; i++) { int a, b; scanf("%d", &a); scanf("%d", &b); g[a].pb(b); g[b].pb(a); } for(int i = 1; i <= n; i++) { memset(d, 0, sizeof(d)); dij(i); for(int j = 1; j <= n; j++) { if(mx < d[j] - 1) { root = i; mx = d[j] - 1; } } } memset(d, 0, sizeof(d)); dij(root); for(int i = 1; i <= n; i++) { if(d[i] - 1 == mx) { v.pb( i ); } } dfs(root); printf("%d\n", ans); } /** 6 1 2 1 3 2 4 4 3 4 5 4 6 **/

Compilation message (stderr)

shymbulak.cpp:57:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
shymbulak.cpp: In function 'int main()':
shymbulak.cpp:59:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
shymbulak.cpp:63:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a);
   ~~~~~^~~~~~~~~~
shymbulak.cpp:64:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &b);
   ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...