Submission #384678

# Submission time Handle Problem Language Result Execution time Memory
384678 2021-04-02T04:43:31 Z zoooma13 Mag (COCI16_mag) C++14
0 / 120
2722 ms 157864 KB
#include <bits/stdc++.h>
using namespace std;

int n ,ans = 0;
vector <vector<int>> adj;
vector <int> x;

int dfs(int u ,int p=-1){
    cout << u << endl;
    int mx = 0 ,mx2 = 0;
    for(int&v : adj[u]) if(v != p){
        int r = dfs(v ,u);
        if(r > mx){
            mx2 = mx;
            mx = r;
        }else if(r > mx2){
            mx2 = r;
        }
    }
    if(x[u] == 1){
        ans = max(ans ,1+mx+mx2);
        return mx+1;
    }
    return 0;
}

int main()
{
    scanf("%d",&n);
    adj.resize(n+1);
    x.resize(n+1);
    for(int a,b,i=1; i<n; i++){
        scanf("%d%d",&a,&b);
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    for(int i=1; i<=n; i++)
        scanf("%d",&x[i]);
    dfs(1);
    if(ans)
        cout << "1/" << ans << endl;
    else
        cout << *min_element(x.begin()+1 ,x.end()) << "/1" << endl;
}

Compilation message

mag.cpp: In function 'int main()':
mag.cpp:29:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   29 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
mag.cpp:33:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   33 |         scanf("%d%d",&a,&b);
      |         ~~~~~^~~~~~~~~~~~~~
mag.cpp:38:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   38 |         scanf("%d",&x[i]);
      |         ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2159 ms 98052 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2722 ms 157864 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 2636 ms 80948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2662 ms 84084 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 293 ms 8300 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2464 ms 76896 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2684 ms 81944 KB Output isn't correct
2 Halted 0 ms 0 KB -