QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#300576#5042. FlowSaanteye#RE 1ms5532kbC++171.6kb2024-01-08 14:37:212024-01-08 14:37:21

Judging History

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

  • [2024-01-08 14:37:21]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:5532kb
  • [2024-01-08 14:37:21]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef pair<int, int> PII;
const int N = 1e5 + 10, M = 2e5 + 10;
//#define p first
//#define d second

int head[N], nxt[M], to[M], cap[N], cnt;
void add_edge(int u, int v, int w){
    to[++cnt] = v, nxt[cnt] = head[u], head[u] = cnt, cap[cnt] = w;
}
int n, m, sum;
vector<vector<int>> v;
void dfs(int u, vector<int>& tmp){
    for(int i = head[u]; i; i = nxt[i]){
        tmp.push_back(cap[i]);
        sum += cap[i];
        dfs(to[i], tmp);
    }
}
void solve(){
    cin >> n >> m;
    for(int i = 1; i <= m; i++){
        int x, y, w;
        cin >> x >> y >> w;
        add_edge(x, y, w);
    }
    for(int i = head[1]; i; i = nxt[i]){
        vector<int> tmp;
        tmp.push_back(cap[i]);
        sum += cap[i];
        dfs(to[i], tmp);
        v.push_back(tmp);
    }
    int k = sum / v[0].size();
    vector<PII> p;
    for(int i = 0; i < v.size(); i++){
        sort(v[i].begin(), v[i].end());
        k -= v[i][0];
        for(int j = 1; j < v[i].size(); j++){
            if(v[i][j] != v[i][j - 1])
                p.push_back({j, v[i][j] - v[i][j - 1]});
        }
    }
    sort(p.begin(), p.end());
    int ans = 0;
    for(int i = 0; i < p.size(); i++){
        if(k >= p[i].second){
            ans += p[i].first * p[i].second;
            k -= p[i].second;
        }
        else{
            ans += p[i].first * k;
            break;
        }
    }
    cout << ans << endl;
}

signed main(){
    ios::sync_with_stdio(false);cin.tie(0);
    int _ = 1;
//    cin >> _;
    while(_--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 3
1 2 1
2 3 2
3 4 3

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 1ms
memory: 5528kb

input:

4 4
1 2 1
1 3 1
2 4 2
3 4 2

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: -100
Runtime Error

input:

100000 199996
1 2 0
1 3 0
1 4 0
1 5 0
1 6 0
1 7 0
1 8 0
1 9 0
1 10 0
1 11 0
1 12 0
1 13 0
1 14 0
1 15 0
1 16 0
1 17 0
1 18 0
1 19 0
1 20 0
1 21 0
1 22 0
1 23 0
1 24 0
1 25 0
1 26 0
1 27 0
1 28 0
1 29 0
1 30 0
1 31 0
1 32 0
1 33 0
1 34 0
1 35 0
1 36 0
1 37 0
1 38 0
1 39 0
1 40 0
1 41 0
1 42 0
1 43 0
...

output:


result: