QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#555891#5102. Dungeon CrawlerevirirCompile Error//C++201.6kb2024-09-10 11:55:352024-09-10 11:55:35

Judging History

你现在查看的是最新测评结果

  • [2024-09-10 11:55:35]
  • 评测
  • [2024-09-10 11:55:35]
  • 提交

answer

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

#define forn(i,a,b) for(int i=(a);i<(b);i++)
#define fore(i,a,b) for(int i=(a);i<=(b);i++)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define F first
#define S second
#define pb push_back
using ll = long long;
using ii = pair<ll, ll>;
using ld = long double;

template<class T> void amax(T& x, T y){ x = max(x, y); }
template<class T> void amin(T& x, T y){ x = min(x, y); }

static constexpr int MAXN = 2005;

int n,Q;
vector<ii> adj[MAXN];
ll dep[MAXN];
bool ok = 1;
bool nice = 0;
ll sumw = 0;
ll mx = 0;

void dfs(int u, int p, int k, int t, bool subt, bool subk)
{
    if (subt && u == k) ok = 0;
    if (subk && u == t) nice = 1;
    subt |= u == t;
    subk |= u == k;
    if (!subk) amax(mx, dep[u]);
    for (const auto& [v, w] : adj[u])
    {
        if (v == p) continue;
        dep[v] = dep[u] + w;
        dfs(v, u, k, t, subt, subk);
    }
}

void solve(int s, int k, int t)
{
    dep[s] = 0;
    mx = 0;
    ok = 1;
    nice = 0;
    dfs(s, -1, k, t, 0, 0);
    if (!ok)
    {
        cout<<"impossible\n";
        return;
    }
    if (nice)
    {
        mx = 0;
        forn(i,0,n) mx = max(mx, dep[i]);
    }
    cout << 2 * sumw - mx << '\n';
}

int main()
{
    cin.tie(0)->sync_with_stdio(0);

    cin>>n>>Q;
    forn(i,0,n-1)
    {
        int u,v; ll w; cin>>u>>v>>w; u--; v--;
        adj[u].pb({v, w});
        adj[v].pb({u, w});
        sumw += w;
    }
    forn(z,0,Q)
    {
        int s,k,t; cin>>s>>k>>t; s--; k--; t--;
        solve(s, k, t);
    }

    return 0;
}

詳細信息

answer.code:24:6: error: ‘bool nice’ redeclared as different kind of entity
   24 | bool nice = 0;
      |      ^~~~
In file included from /usr/include/c++/13/bits/atomic_wait.h:44,
                 from /usr/include/c++/13/bits/atomic_base.h:42,
                 from /usr/include/c++/13/bits/shared_ptr_atomic.h:33,
                 from /usr/include/c++/13/memory:81,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:56,
                 from answer.code:1:
/usr/include/unistd.h:598:12: note: previous declaration ‘int nice(int)’
  598 | extern int nice (int __inc) __THROW __wur;
      |            ^~~~
answer.code: In function ‘void dfs(int, int, int, int, bool, bool)’:
answer.code:31:30: error: assignment of function ‘int nice(int)’
   31 |     if (subk && u == t) nice = 1;
      |                         ~~~~~^~~
answer.code: In function ‘void solve(int, int, int)’:
answer.code:48:10: error: assignment of function ‘int nice(int)’
   48 |     nice = 0;
      |     ~~~~~^~~