답안 #1102918

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1102918 2024-10-19T08:49:11 Z Cadoc Hotspot (NOI17_hotspot) C++14
100 / 100
568 ms 5456 KB
/*
    Author: Cadocx
    Codeforces: https://codeforces.com/profile/Kadoc
    VNOJ: oj.vnoi.info/user/Cadoc
*/

#include <bits/stdc++.h>
using namespace std;

// input/output
#define fastIO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define el cout << '\n'
#define debug(x) cout << #x << " = " << x << '\n'
#define execute cerr << "Time elapsed: " << (1.0 * clock() / CLOCKS_PER_SEC) << "s"
// #pragma GCC optimize("O2", "unroll-loops", "Ofast")
// #pragma GCC target("avx,avx2,fma")
//data type
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define piv pair<int, vector<int>>
#define vi vector<int>
#define vl vector<ll>
#define vc vector<char>
template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return 1; }; return 0; }
template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return 1; }; return 0; }
//STL
#define sz(x) (int)(x).size()
#define FOR(i,l,r) for(auto i = l; i <= r; i++)
#define FORD(i,r,l) for(auto i = r; i >= l; i--)
#define forin(i,a) for(auto i : a)
#define pb push_back
#define eb emplace_back
#define pf push_front
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
//bitmask
#define bitcnt(n) __builtin_popcount(n)
#define mask(i) (1 << (i))
#define bit(n, i) (((n) >> (i)) & 1)
#define set_on(n, i) ((n) | mask(i))
#define set_off(n, i) ((n) & ~mask(i))
//constant
#define N 100005
#define MOD 1000230007
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define base 31
#define Kadoc 0

int n, m, q;
int d[2][N];
ll cnt[2][N];
long double f[N];
vector<int> g[N];

void ditcha(int d[], ll cnt[], int s){
	queue<int> q;
	FOR(i, 0, n-1) d[i] = -1, cnt[i] = 0;

	d[s] = 0;
	cnt[s] = 1;
	q.push(s);

	while(q.size()){
		int u = q.front(); q.pop();

		for(int v:g[u]){
			if(d[v] < 0){
				d[v] = d[u] + 1;
				cnt[v] = cnt[u];
				q.push(v);
			}
			else if(d[v] == d[u] + 1) cnt[v] += cnt[u];
		}
	}
}

void solve(){
    cin >> n >> m;
    FOR(i, 1, m){
    	int u, v; cin >> u >> v;
    	g[u].pb(v);
    	g[v].pb(u);
    }

    cin >> q;
    while(q--){
    	int u, v; cin >> u >> v;

    	ditcha(d[0], cnt[0], u);
    	ditcha(d[1], cnt[1], v);

    	FOR(i, 0, n-1) if(d[0][i] + d[1][i] == d[0][v]){
    		ll tot = cnt[0][i] * cnt[1][i];
    		f[i] += (long double) tot / (long double) cnt[0][v];
    	}
    }

    int Ans = -1;
    FOR(i, 0, n-1) if(Ans < 0 || f[Ans] < f[i]) Ans = i;

    cout << Ans;
}

int main(){
    #define NAME "TASK"
    if(fopen(NAME".inp", "r")){
        freopen(NAME".inp", "r", stdin);
        freopen(NAME".out", "w", stdout);
    }

    fastIO;
    
    if(Kadoc){
        int tc; cin >> tc;
        while(tc--){
            solve();
        }
    } else solve();
}

Compilation message

hotspot.cpp: In function 'int main()':
hotspot.cpp:111:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  111 |         freopen(NAME".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
hotspot.cpp:112:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  112 |         freopen(NAME".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4700 KB Output is correct
2 Correct 2 ms 4712 KB Output is correct
3 Correct 1 ms 4688 KB Output is correct
4 Correct 1 ms 4688 KB Output is correct
5 Correct 2 ms 4688 KB Output is correct
6 Correct 2 ms 4688 KB Output is correct
7 Correct 1 ms 4688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4700 KB Output is correct
2 Correct 2 ms 4712 KB Output is correct
3 Correct 1 ms 4688 KB Output is correct
4 Correct 1 ms 4688 KB Output is correct
5 Correct 2 ms 4688 KB Output is correct
6 Correct 2 ms 4688 KB Output is correct
7 Correct 1 ms 4688 KB Output is correct
8 Correct 2 ms 4688 KB Output is correct
9 Correct 2 ms 4768 KB Output is correct
10 Correct 1 ms 4688 KB Output is correct
11 Correct 2 ms 4688 KB Output is correct
12 Correct 1 ms 4688 KB Output is correct
13 Correct 2 ms 4688 KB Output is correct
14 Correct 2 ms 4688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4700 KB Output is correct
2 Correct 2 ms 4712 KB Output is correct
3 Correct 1 ms 4688 KB Output is correct
4 Correct 1 ms 4688 KB Output is correct
5 Correct 2 ms 4688 KB Output is correct
6 Correct 2 ms 4688 KB Output is correct
7 Correct 1 ms 4688 KB Output is correct
8 Correct 2 ms 4688 KB Output is correct
9 Correct 3 ms 4688 KB Output is correct
10 Correct 3 ms 4688 KB Output is correct
11 Correct 3 ms 4688 KB Output is correct
12 Correct 2 ms 4688 KB Output is correct
13 Correct 2 ms 4688 KB Output is correct
14 Correct 3 ms 4688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4700 KB Output is correct
2 Correct 2 ms 4712 KB Output is correct
3 Correct 1 ms 4688 KB Output is correct
4 Correct 1 ms 4688 KB Output is correct
5 Correct 2 ms 4688 KB Output is correct
6 Correct 2 ms 4688 KB Output is correct
7 Correct 1 ms 4688 KB Output is correct
8 Correct 2 ms 4688 KB Output is correct
9 Correct 2 ms 4768 KB Output is correct
10 Correct 1 ms 4688 KB Output is correct
11 Correct 2 ms 4688 KB Output is correct
12 Correct 1 ms 4688 KB Output is correct
13 Correct 2 ms 4688 KB Output is correct
14 Correct 2 ms 4688 KB Output is correct
15 Correct 2 ms 4688 KB Output is correct
16 Correct 3 ms 4688 KB Output is correct
17 Correct 3 ms 4688 KB Output is correct
18 Correct 3 ms 4688 KB Output is correct
19 Correct 2 ms 4688 KB Output is correct
20 Correct 2 ms 4688 KB Output is correct
21 Correct 3 ms 4688 KB Output is correct
22 Correct 2 ms 4688 KB Output is correct
23 Correct 2 ms 4688 KB Output is correct
24 Correct 2 ms 4688 KB Output is correct
25 Correct 3 ms 4864 KB Output is correct
26 Correct 3 ms 4860 KB Output is correct
27 Correct 2 ms 4688 KB Output is correct
28 Correct 3 ms 4688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4700 KB Output is correct
2 Correct 2 ms 4712 KB Output is correct
3 Correct 1 ms 4688 KB Output is correct
4 Correct 1 ms 4688 KB Output is correct
5 Correct 2 ms 4688 KB Output is correct
6 Correct 2 ms 4688 KB Output is correct
7 Correct 1 ms 4688 KB Output is correct
8 Correct 2 ms 4688 KB Output is correct
9 Correct 2 ms 4768 KB Output is correct
10 Correct 1 ms 4688 KB Output is correct
11 Correct 2 ms 4688 KB Output is correct
12 Correct 1 ms 4688 KB Output is correct
13 Correct 2 ms 4688 KB Output is correct
14 Correct 2 ms 4688 KB Output is correct
15 Correct 3 ms 4688 KB Output is correct
16 Correct 2 ms 4820 KB Output is correct
17 Correct 4 ms 4688 KB Output is correct
18 Correct 3 ms 4848 KB Output is correct
19 Correct 5 ms 4688 KB Output is correct
20 Correct 3 ms 4688 KB Output is correct
21 Correct 3 ms 4688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4700 KB Output is correct
2 Correct 2 ms 4712 KB Output is correct
3 Correct 1 ms 4688 KB Output is correct
4 Correct 1 ms 4688 KB Output is correct
5 Correct 2 ms 4688 KB Output is correct
6 Correct 2 ms 4688 KB Output is correct
7 Correct 1 ms 4688 KB Output is correct
8 Correct 2 ms 4688 KB Output is correct
9 Correct 2 ms 4768 KB Output is correct
10 Correct 1 ms 4688 KB Output is correct
11 Correct 2 ms 4688 KB Output is correct
12 Correct 1 ms 4688 KB Output is correct
13 Correct 2 ms 4688 KB Output is correct
14 Correct 2 ms 4688 KB Output is correct
15 Correct 2 ms 4688 KB Output is correct
16 Correct 3 ms 4688 KB Output is correct
17 Correct 3 ms 4688 KB Output is correct
18 Correct 3 ms 4688 KB Output is correct
19 Correct 2 ms 4688 KB Output is correct
20 Correct 2 ms 4688 KB Output is correct
21 Correct 3 ms 4688 KB Output is correct
22 Correct 2 ms 4688 KB Output is correct
23 Correct 2 ms 4688 KB Output is correct
24 Correct 2 ms 4688 KB Output is correct
25 Correct 3 ms 4864 KB Output is correct
26 Correct 3 ms 4860 KB Output is correct
27 Correct 2 ms 4688 KB Output is correct
28 Correct 3 ms 4688 KB Output is correct
29 Correct 3 ms 4688 KB Output is correct
30 Correct 2 ms 4820 KB Output is correct
31 Correct 4 ms 4688 KB Output is correct
32 Correct 3 ms 4848 KB Output is correct
33 Correct 5 ms 4688 KB Output is correct
34 Correct 3 ms 4688 KB Output is correct
35 Correct 3 ms 4688 KB Output is correct
36 Correct 47 ms 4944 KB Output is correct
37 Correct 107 ms 4944 KB Output is correct
38 Correct 568 ms 5416 KB Output is correct
39 Correct 353 ms 5268 KB Output is correct
40 Correct 57 ms 4944 KB Output is correct
41 Correct 343 ms 5368 KB Output is correct
42 Correct 486 ms 5456 KB Output is correct
43 Correct 24 ms 4944 KB Output is correct
44 Correct 20 ms 4944 KB Output is correct