QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#210220#5492. Toll Roadshagry#WA 283ms61028kbC++142.7kb2023-10-11 09:31:142023-10-11 09:31:14

Judging History

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

  • [2023-10-11 09:31:14]
  • 评测
  • 测评结果:WA
  • 用时:283ms
  • 内存:61028kb
  • [2023-10-11 09:31:14]
  • 提交

answer

#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define MP make_pair
#define all(x) x.begin(),x.end()
#define Hagry ios::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);

using namespace std;
using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
using vpi = vector <pair<int, int>>;
using vvi = vector <vector<int>>;
using ti = tuple<int,int,int>;
const int OO = 1e9 + 5;
const int N = 2e5 + 5;

struct Record{
    int comp, weight, sz;
    Record(){}
    Record(int comp, int weight, int sz):comp(comp), weight(weight), sz(sz){}
};

struct DSU{
    vi par, sz;
    vvi childs;
    //comp after merge, weight, size after merge
    vector<vector<Record>> merges;

    DSU(int n){
        par.resize(n + 1);
        sz.resize(n+1);
        childs.resize(n+1);
        merges.resize(n+1);
        for(int i=1; i<=n; ++i){
            par[i] = i;
            sz[i] = 1;
            merges[i].pb({i, 0, 1});
            childs[i].pb(i);
        }
    }

    int find(int a){
        if(a == par[a])return a;
        return find(par[a]);
    }

    void unite(int a, int b, int w){
        a = find(a);
        b = find(b);
        if(a == b)return;
        if(sz[a] > sz[b])
            swap(a, b);

        par[a] = b;
        sz[b] += sz[a];
        for(int c:childs[a]){
            childs[b].pb(c);
            merges[c].pb({b, w, sz[b]});
        }
        childs[a].clear();
    }

};

struct Edge{
    int a, b, w;
    Edge(){}
    Edge(int a, int b, int w):a(a), b(b), w(w){
    }
    bool operator<(const Edge& e2){
        return w < e2.w;
    }
};

void TC(){
    int n, m, q;
    cin >> n >> m >> q;

    vector<Edge> edges;
    int a, b, w;
    for(int i=0; i<m; ++i){
        cin >> a >> b>> w;
        edges.pb(Edge(a, b, w));
    }
    sort(all(edges));

    DSU dsu(n);
    for(auto e:edges){
        dsu.unite(e.a, e.b, e.w);
    }

    while(q--){
        cin >> a >> b;
        auto v1 = dsu.merges[a];
        auto v2 = dsu.merges[b];
        map<int,int> ind;
        for(int i=0; i<v2.size(); ++i)
            ind[v2[i].comp] = i;

        for(auto e:v1){
            if(ind.find(e.comp) != ind.end()){
                auto e2= v2[ind[e.comp]];
                cout << max(e.weight, e2.weight) << " ";
                cout << max(e.sz, e2.sz) << "\n";
                break;
            }
        }
    }
}

int32_t main() {
#ifndef ONLINE_JUDGE
    freopen("input.in", "r", stdin); freopen("output.out", "w", stdout);
#endif
    Hagry
    int t = 1;
//    cin >> t;
    while (t--) {
        TC();
//        cout << '\n';
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3888kb

input:

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

output:

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

result:

ok 6 lines

Test #2:

score: -100
Wrong Answer
time: 283ms
memory: 61028kb

input:

200000 199999 200000
40203 148773 165038
148773 54931 77889
54931 9912 192188
9912 180491 24730
180491 77332 36976
77332 43929 146532
43929 43341 172446
43341 141304 121793
141304 105828 148202
105828 72010 107746
72010 152016 156358
152016 150074 115703
150074 117105 73900
117105 57831 59264
57831 ...

output:

165038 3
77889 2
192188 41
24730 2
36976 3
146532 4
172446 20
121793 2
148202 4
107746 2
156358 10
115703 6
73900 5
59264 2
67443 4
26999 2
156979 16
80963 3
56618 2
107615 6
63765 3
19719 2
178439 35
95141 5
72029 4
14650 2
21437 3
109944 6
139220 7
141978 9
102949 2
170997 15
100704 3
75249 2
1312...

result:

wrong answer 14489th lines differ - expected: '186821 91', found: '186821 60'