이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define int long long
#define F first
#define S second
#define MAXN 5005
#define MAXEDGE 40005
#define ii pair<ll,int>
#define bit(i,j) ((i>>j)&1)
#define sz(i) (int)i.size()
#define endl '\n'
using namespace std;
int n, m, k;
vector<int>g[MAXN];
namespace sub1
{
long double dp[MAXN];
ii d[MAXN][2];
void bfs(int st, int j)
{
for(int i = 0; i <= n; i++)
d[i][j] = {1e18, 0};
queue<int>q;
q.push(st);
d[st][j] = {0, 1};
while(q.empty() != 1)
{
int u = q.front();
q.pop();
for(int v : g[u])
{
if(d[v][j].F > d[u][j].F + 1)
{
d[v][j] = {d[u][j].F + 1, d[u][j].S};
q.push(v);
}
else if(d[v][j].F == d[u][j].F + 1)
d[v][j].S += d[u][j].S;
}
}
}
void calc(int st, int ed)
{
queue<int>q;
q.push(ed);
while(q.empty() != 1)
{
int u = q.front();
q.pop();
dp[u] += (long double)(1LL*d[u][0].S * d[u][1].S / d[ed][0].S);
for(int v : g[u])
if(d[v][0].F + 1 == d[u][0].F)
q.push(v);
}
}
void solve()
{
cin >> k;
for(int i = 1; i <= k; i++)
{
int x, y;
cin >> x >> y;
bfs(x, 0);
bfs(y, 1);
calc(x, y);
}
int pos;
long double res = 0;
for(int i = 1; i <= n; i++)
if(dp[i] > res)
{
res = dp[i];
pos = i;
}
cout << pos;
}
}
main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for(int i = 1; i <= m; i++)
{
int x, y;
cin >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
}
sub1::solve();
}
컴파일 시 표준 에러 (stderr) 메시지
hotspot.cpp:78:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
78 | main()
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |