Submission #426619

# Submission time Handle Problem Language Result Execution time Memory
426619 2021-06-14T07:58:12 Z TLP39 Hotspot (NOI17_hotspot) C++14
100 / 100
1076 ms 1180 KB
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,pair<int,int>> pii;
 
int n,m,k;
vector<int> adj[5003];
int shortest_path[2][5003];
int num_shortest_path[2][5003];
bool marked[2][5003];
double final[5003];
 
void bfs(int a,int pos)
{
  for(int i=0;i<n;i++) 
  {
    marked[pos][i]=false;
    shortest_path[pos][i]=1000000;
    num_shortest_path[pos][i]=0;
  }
  queue<int> q;
  int temp;
  q.push(a);
  marked[pos][a]=true;
  shortest_path[pos][a]=0;
  num_shortest_path[pos][a]=1;
  while(!q.empty())
  {
   	temp=q.front();
    q.pop();
    for(int i=0;i<adj[temp].size();i++)
    {
       	if(shortest_path[pos][adj[temp][i]]<=shortest_path[pos][temp]) continue;
        if(!marked[pos][adj[temp][i]])
        {
          marked[pos][adj[temp][i]]=true;
          shortest_path[pos][adj[temp][i]]=shortest_path[pos][temp]+1;
          q.push(adj[temp][i]);
        }
        num_shortest_path[pos][adj[temp][i]]+=num_shortest_path[pos][temp];
     }
  }
}
 
int main()
{
  scanf("%d %d",&n,&m);
  int u,v;
  for(int i=0;i<m;i++)
  {
    scanf("%d %d",&u,&v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  for(int i=0;i<n;i++) final[i]=(double)0;
  scanf("%d",&k);
  while(k--)
  {
    scanf("%d %d",&u,&v);
    bfs(u,0);
    bfs(v,1);
    for(int i=0;i<n;i++)
    {
      if(shortest_path[0][v]!=shortest_path[0][i]+shortest_path[1][i]) continue;
      final[i]+=((double)(num_shortest_path[0][i]*num_shortest_path[1][i]))/((double)(num_shortest_path[0][v]));
    }
  }
  double maxi=(double)(-1);
  int posi=-1;
  for(int i=0;i<n;i++)
  {
    if(final[i]>maxi)
    {
      maxi=final[i];
      posi=i;
    }
  }
  printf("%d",posi);
}

Compilation message

hotspot.cpp: In function 'void bfs(int, int)':
hotspot.cpp:30:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     for(int i=0;i<adj[temp].size();i++)
      |                 ~^~~~~~~~~~~~~~~~~
hotspot.cpp: In function 'int main()':
hotspot.cpp:46:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |   scanf("%d %d",&n,&m);
      |   ~~~~~^~~~~~~~~~~~~~~
hotspot.cpp:50:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |     scanf("%d %d",&u,&v);
      |     ~~~~~^~~~~~~~~~~~~~~
hotspot.cpp:55:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |   scanf("%d",&k);
      |   ~~~~~^~~~~~~~~
hotspot.cpp:58:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |     scanf("%d %d",&u,&v);
      |     ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 416 KB Output is correct
5 Correct 1 ms 416 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 416 KB Output is correct
5 Correct 1 ms 416 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 416 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 416 KB Output is correct
5 Correct 1 ms 416 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 3 ms 460 KB Output is correct
10 Correct 3 ms 460 KB Output is correct
11 Correct 4 ms 420 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 4 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 416 KB Output is correct
5 Correct 1 ms 416 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 416 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 3 ms 460 KB Output is correct
17 Correct 3 ms 460 KB Output is correct
18 Correct 4 ms 420 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 4 ms 460 KB Output is correct
22 Correct 2 ms 460 KB Output is correct
23 Correct 2 ms 460 KB Output is correct
24 Correct 4 ms 460 KB Output is correct
25 Correct 5 ms 460 KB Output is correct
26 Correct 5 ms 460 KB Output is correct
27 Correct 2 ms 332 KB Output is correct
28 Correct 4 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 416 KB Output is correct
5 Correct 1 ms 416 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 416 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 3 ms 460 KB Output is correct
16 Correct 2 ms 460 KB Output is correct
17 Correct 6 ms 632 KB Output is correct
18 Correct 3 ms 460 KB Output is correct
19 Correct 6 ms 588 KB Output is correct
20 Correct 3 ms 460 KB Output is correct
21 Correct 2 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 416 KB Output is correct
5 Correct 1 ms 416 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 416 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 3 ms 460 KB Output is correct
17 Correct 3 ms 460 KB Output is correct
18 Correct 4 ms 420 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 4 ms 460 KB Output is correct
22 Correct 2 ms 460 KB Output is correct
23 Correct 2 ms 460 KB Output is correct
24 Correct 4 ms 460 KB Output is correct
25 Correct 5 ms 460 KB Output is correct
26 Correct 5 ms 460 KB Output is correct
27 Correct 2 ms 332 KB Output is correct
28 Correct 4 ms 460 KB Output is correct
29 Correct 3 ms 460 KB Output is correct
30 Correct 2 ms 460 KB Output is correct
31 Correct 6 ms 632 KB Output is correct
32 Correct 3 ms 460 KB Output is correct
33 Correct 6 ms 588 KB Output is correct
34 Correct 3 ms 460 KB Output is correct
35 Correct 2 ms 460 KB Output is correct
36 Correct 88 ms 648 KB Output is correct
37 Correct 202 ms 736 KB Output is correct
38 Correct 1076 ms 1104 KB Output is correct
39 Correct 739 ms 1144 KB Output is correct
40 Correct 127 ms 716 KB Output is correct
41 Correct 648 ms 1112 KB Output is correct
42 Correct 875 ms 1180 KB Output is correct
43 Correct 51 ms 588 KB Output is correct
44 Correct 52 ms 624 KB Output is correct