QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#420905#6523. Escape PlangabrielwuWA 1089ms77460kbC++202.4kb2024-05-25 03:12:272024-05-25 03:12:27

Judging History

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

  • [2024-05-25 03:12:27]
  • 评测
  • 测评结果:WA
  • 用时:1089ms
  • 内存:77460kb
  • [2024-05-25 03:12:27]
  • 提交

answer

// right side, 8th row, inner table, harvard

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

#define forn(i, n) for(int i=0; i<(n); i++)
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define f first
#define s second

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
	cout << "[";
	forn(i, (int)v.size()) {
		if(i) cout << ", ";
		cout << v[i];
	}
	return cout << "]";
}
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) {
	return cout << "(" << p.f << ", " << p.s << ")";
}

int n, m, k;
vector<int> e, d;
vector<ll> dist;
vector<vector<pair<int, ll>>> adj;
vector<multiset<ll>> ss;
vector<bool> vis;

void test() {
    cin >> n >> m >> k;
    e.resize(k); forn(i,k) cin >> e[i];
    d.resize(n); forn(i,n) cin >> d[i];
    adj.clear(); adj.resize(n);
    forn(i,n) adj[i].clear();
    forn(i,m) {
        int u,v,w; cin >> u >> v >> w; u--; v--;
        adj[u].pb(mp(v,w));
        adj[v].pb(mp(u,w));
    }

    ss.clear(); ss.resize(n);
    forn(i,n) ss[i].clear();
    dist.assign(n, 1e18);
    priority_queue<pll, vector<pll>, greater<pll>> pq;
    for (int exit : e) {
        exit--;
        pq.push(mp(0,exit));
        dist[exit] = 0;
    }
    vis.assign(n, false);

    while (! pq.empty()) {
        pll cur = pq.top(); pq.pop();
        ll u = cur.s;
        if (vis[u]) continue;
        vis[u] = true;
        for (pii p : adj[u]) {
            ll nb = p.f, w = p.s;
            ss[nb].insert(dist[u]+w);
            while (ss[nb].size() > d[nb]+1) {
                auto it = ss[nb].end(); it--; ss[nb].erase(it);
            }
            if (ss[nb].size() > d[nb]) {
                auto it = ss[nb].end(); it--; 
                // if (dist[nb] > *it) {
                    dist[nb] = *it;
                    pq.push(mp(*it, nb));
                // }
            }
        }
        // cout << u << endl;
        // forn(i, n) {
        //     cout << i << ": ";
        //     for (int j : ss[i]) cout << j << ' ';
        //     cout << '\n';
        // }
    }
    if (dist[0]==1e18) cout << -1 << '\n';
    else cout << dist[0] << '\n';
}

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

    int t; cin >> t;
    while (t--) test();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

4
-1

result:

ok 2 number(s): "4 -1"

Test #2:

score: -100
Wrong Answer
time: 1089ms
memory: 77460kb

input:

100
100 1808 2
94 47
3 3 0 2 4 3 3 4 0 0 2 2 2 3 2 4 0 2 3 4 4 2 0 3 4 3 1 0 2 1 2 2 0 3 4 4 4 1 2 2 3 1 0 0 3 1 4 2 1 3 3 4 3 0 4 1 0 3 2 1 4 4 1 3 2 3 3 3 3 1 0 3 0 4 3 1 0 4 0 4 4 1 2 0 0 4 1 3 3 3 0 2 2 1 1 2 3 4 1 2
72 29 1138
59 78 2398
95 5 1610
32 46 4176
36 99 8143
100 69 413
61 58 1595
9 9...

output:

5109
1725
3293
5074
3796
3394
1912
6772
2329
2067
3296
2809
865
4249
2241
3792
2135
2544
3343
1775
10602
4677
1700
2150
7071
14055
3368
2322
1113
1980
3067
1735
1702
-1
2879
6265
2065
2855
2433
3001
402
3769
18118
6874
7879
3823
-1
836
2636
10564
-1
3166
3615
7526
5549
1261
3302
270
4440
2639
3350
3...

result:

wrong answer 2nd numbers differ - expected: '1021', found: '1725'