QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#882296#7938. Graph RacekhanhphucscratchWA 1ms14052kbC++201.9kb2025-02-04 23:22:132025-02-04 23:22:14

Judging History

This is the latest submission verdict.

  • [2025-02-04 23:22:14]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 14052kb
  • [2025-02-04 23:22:13]
  • Submitted

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
vector<int> ad[300005], dag[600005];
int dp[600005], dis[300005], ans[300005], a[300005], b[300005];
void dfs(int u)
{
    int re = -1e18;
    for(int v : dag[u]){
        dfs(v);
        re = max(re, dp[v]);
    }
    dp[u] = max(dp[u], re);
    ans[u] = max(ans[u], re);
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin>>n>>m;
    for(int i = 1; i <= n; i++) cin>>a[i]>>b[i];
    vector<pair<int, int>> edges;
    for(int i = 1; i <= m; i++){
        int u, v; cin>>u>>v;
        edges.push_back({u, v});
        ad[u].push_back(v);
        ad[v].push_back(u);
    }
    memset(dis, 0x3f, sizeof(dis)); dis[1] = 0;
    queue<int> w; w.push(1);
    while(w.size() > 0){
        int u = w.front(); w.pop();
        for(int v : ad[u]) if(dis[v] > dis[u]+1){
            dis[v] = dis[u]+1;
            w.push(v);
        }
    }
    pair<int, int> maxval = make_pair(-1e18, -1e18);
    for(int i = 1; i <= n; i++){
        int val = a[i] - (dis[i]+1) * b[i];
        if(maxval.second < val) maxval.second = val;
        if(maxval.first < maxval.second) swap(maxval.first, maxval.second);
    }
    for(int i = 1; i <= n; i++){
        if(a[i] - dis[i] * b[i] == maxval.first) ans[i] = maxval.second;
        else ans[i] = maxval.first;
    }
    for(pair<int, int> i : edges){
        if(dis[i.first] > dis[i.second]) swap(i.first, i.second);
        if(dis[i.first] == dis[i.second]){
            dag[i.first].push_back(i.second+n);
        }
        else{
            dag[i.first].push_back(i.second);
            dag[i.first+n].push_back(i.second+n);
        }
    }
    for(int i = 1; i <= n; i++){
        dp[i] = a[i] - (dis[i]-1) * b[i];
        dp[i+n] = a[i] - dis[i] * b[i];
    }
    //cout<<"A"<<dis[4]<<endl;
    dfs(1);
    sort(ad[1].begin(), ad[1].end());
    for(int v : ad[1]) cout<<ans[v]<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 12004kb

input:

5 4
0 0
1 1
1 1
5 1
100 40
4 1
1 2
1 3
4 5

output:

3
3
60

result:

ok 3 number(s): "3 3 60"

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 14052kb

input:

6 10
903568159 700448725
628912797 731062359
620179636 21330815
551246171 800423583
200754983 633226914
263013360 961926530
3 5
3 6
5 2
4 2
4 3
1 3
6 2
4 5
6 4
3 2

output:

577518006

result:

wrong answer 1st numbers differ - expected: '203119434', found: '577518006'