답안 #162765

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
162765 2019-11-09T16:10:27 Z _qVp_ Mag (COCI16_mag) C++14
24 / 120
569 ms 90432 KB
#include <bits/stdc++.h>

using namespace std;

const int md = 1e6 + 10;

vector < int > adj[md];
int d[md], f[md], a[md], u[md], v[md];
queue < int > q;
int n;

int bfs(int s) {
    d[s] = 1;
    q.push(s);
    int u = 0;
    while (q.size()) {
        u = q.front(); q.pop();
        for(int i = 0; i < adj[u].size(); i++) {
            int v = adj[u][i];
            if (d[v] > 0)
                continue;
            d[v] = d[u] + 1;
            q.push(v);
        }
    }
    //cout << u << endl;
    f[u] = 1;
    q.push(u);
    while (q.size()) {
        u = q.front(); q.pop();
        for(int i = 0; i < adj[u].size(); i++) {
            int v = adj[u][i];
            if (f[v] > 0)
                continue;
            f[v] = f[u] + 1;
            q.push(v);
        }
    }
    return f[u];
}

int main() {
    //freopen("test.in", "r", stdin);
    ios_base::sync_with_stdio(0);
    cin >> n;
    for(int i = 1; i < n; i++)
        cin >> u[i] >> v[i];
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    for(int i = 1; i < n; i++) {
        //int u, v;
        //cin >> u >> v;
        if (a[u[i]] == 1 && a[v[i]] == 1) {
            adj[u[i]].push_back(v[i]);
            adj[v[i]].push_back(u[i]);
        }        
    }
    long long a1 = 1e9 + 10, b1 = 1;
    for(int i = 1; i <= n; i++) {
        if (d[i] > 0) continue;
        long long b2 = bfs(i);
    //    cout << i << " " << a[i] << " " << b2 << endl; 
        if (a1 * b2 >= b1 * a[i]) {
            a1 = a[i];
            b1 = b2;
        }
    }
    cout << a1 << "/" << b1;
    return 0;
}

Compilation message

mag.cpp: In function 'int bfs(int)':
mag.cpp:18:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 0; i < adj[u].size(); i++) {
                        ~~^~~~~~~~~~~~~~~
mag.cpp:31:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 0; i < adj[u].size(); i++) {
                        ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 23928 KB Output is correct
2 Correct 25 ms 23928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 26 ms 23928 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 422 ms 78424 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 24 ms 23800 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 498 ms 90432 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 504 ms 89548 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 373 ms 59904 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 29816 KB Output is correct
2 Incorrect 503 ms 89648 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 431 ms 79024 KB Output is correct
2 Incorrect 507 ms 90404 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 569 ms 89888 KB Output is correct
2 Correct 395 ms 57692 KB Output is correct