QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#65322#4580. Bicycle Tourtriplem5ds#WA 36ms25892kbC++233.1kb2022-11-29 20:25:582022-11-29 20:26:01

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-29 20:26:01]
  • 评测
  • 测评结果:WA
  • 用时:36ms
  • 内存:25892kb
  • [2022-11-29 20:25:58]
  • 提交

answer

/// Brrrr Brrrr
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")

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

#define pb push_back
#define F first
#define S second
#define f(i, a, b)  for(int i = a; i < b; i++)
#define all(a)  a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) (int)(x).size()
#define mp(x,y) make_pair(x,y)
#define popCnt(x) (__builtin_popcountll(x))
#define int ll

using ll = long long;
using ii = pair<int, int>;
using ull = unsigned long long;

const int N = 1e6+5, LG = 18, MOD = (119 << 23) + 1;
const long double PI = acos(-1);
const long double EPS = 1e-7;

const int dx[] = {0,0,1,-1};
const int dy[] = {1,-1,0,0};

int n, m;
int h[100005];
vector<int> add[100005], del[100005];
vector<int> adj[100005];
int p[100005];
int pa[N][LG], lvl[N];
int in[N], out[N], timer;
void dfs(int u, int p){
  in[u] = ++timer;
  for(int k = 1; k < LG; k++)
    pa[u][k] = pa[pa[u][k-1]][k-1];
  for(auto v : adj[u])
    if(v != p){
       lvl[v] = lvl[u] + 1;
       pa[v][0] = u;
       dfs(v, u);
     }
  out[u] = timer;
}
int LCA(int u, int v){
  if(lvl[u] > lvl[v])
    swap(u,v);
   int d = lvl[v] - lvl[u];
   for(int k = 0; k < LG; k++)
    if(d >> k & 1)
      v = pa[v][k];
   if(u == v)return u;
   for(int i = LG - 1; i >= 0; --i)
    if(pa[u][i] != pa[v][i]){
      u = pa[u][i];
      v = pa[v][i];
    }
  return pa[u][0];
}
int get(int i){return i == p[i]? i : p[i]=get(p[i]);}
multiset<int> mt[100005];
int ans[100005];
void dfs2(int node, int par) {

    for(auto v : adj[node]) if(v!=par){
        dfs2(v, node);
        if(mt[v].size() > mt[node].size()) {
            swap(mt[node], mt[v]);
        }
        for(auto x : mt[v])mt[node].insert(x);
        mt[v].clear();
    }
    for(auto x : add[node])mt[node].insert(x);
    if(mt[node].size())ans[node] = *mt[node].begin();
    for(auto x : del[node])mt[node].erase(x);
}
void doWork() {

    memset(ans,-1,sizeof ans);

    cin >> n >> m;
    f(i,1,n+1)
        cin >> h[i], p[i]=i;
    vector<vector<int>> edges, extra;
    f(i,0,m) {
        int u, v;
        cin >> u >> v;
        edges.push_back({abs(h[u]-h[v]), u, v});
    }

    sort(all(edges));

    for(auto e : edges) {
        int w = e[0], v = e[1], u = e[2];
        if(get(u)==get(v)) {
            extra.push_back(e);
        }   else {
            adj[u].pb(v);
            adj[v].pb(u);
            p[get(u)] = get(v);
        }
    }

    dfs(1, 1);

    for(auto e : extra) {
        int w = e[0], v = e[1], u = e[2];
        if(lvl[u] > lvl[v])swap(u,v);
        int lca = LCA(u,v);
        if(lca == u)add[v].pb(w), del[u].pb(w);
        else {
            add[u].pb(w);
            add[v].pb(w);
            del[lca].pb(w);
        }
    }

    dfs2(1, 1);
    f(i,1,n+1)
        cout << ans[i] << " \n"[i==n];


}
int32_t main() {
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif // ONLINE_JUDGE


    int t = 1;
//    cin >> t;
    while (t--) {
        doWork();
    }
    return 0;
}

///Look at my code ya codeomk

詳細信息

Test #1:

score: 100
Accepted
time: 4ms
memory: 21164kb

input:

8 11
5 2 7 0 10 6 6 6
1 2
1 3
2 3
2 4
2 5
2 7
3 5
1 6
6 7
6 8
7 8

output:

4 4 5 -1 8 0 0 0

result:

ok single line: '4 4 5 -1 8 0 0 0'

Test #2:

score: 0
Accepted
time: 4ms
memory: 20996kb

input:

4 5
10 20 30 40
1 2
1 3
1 4
2 3
3 4

output:

20 20 20 30

result:

ok single line: '20 20 20 30'

Test #3:

score: 0
Accepted
time: 3ms
memory: 20912kb

input:

5 4
72 35 22 49 108
1 2
2 3
3 4
4 5

output:

-1 -1 -1 -1 -1

result:

ok single line: '-1 -1 -1 -1 -1'

Test #4:

score: 0
Accepted
time: 12ms
memory: 19072kb

input:

2 1
10 20
1 2

output:

-1 -1

result:

ok single line: '-1 -1'

Test #5:

score: -100
Wrong Answer
time: 36ms
memory: 25892kb

input:

252 31626
825 5234 3578 4723 2145 4362 1861 2413 7203 1939 3210 7153 2155 4559 4403 1466 887 3786 6529 719 4272 3287 5703 6708 2390 4987 4214 770 3487 6230 3498 6255 4963 1093 3065 2961 1663 4857 3224 4284 4228 106 1614 1010 145 1557 4510 1032 4632 155 5570 154 884 1204 2876 6163 5023 4593 7261 3729...

output:

55 33 46 34 10 33 34 30 22 33 33 46 10 34 26 100 14 62 17 9 13 35 81 45 23 29 23 25 11 32 11 32 29 38 18 13 14 0 28 13 11 42 35 22 9 57 22 22 35 7 52 7 14 45 72 92 14 8 15 62 10 20 21 34 66 9 20 24 29 6 30 16 26 9 6 27 8 40 94 17 12 26 29 17 10 61 35 9 39 15 14 14 31 22 63 66 110 24 16 7 30 22 15 18...

result:

wrong answer 1st lines differ - expected: '55 33 46 34 10 33 34 30 22 33 ...45 15 71 10 52 18 16 30 10 34 4', found: '55 33 46 34 10 33 34 30 22 33 ...45 15 71 10 52 18 16 30 10 34 4'