답안 #525632

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
525632 2022-02-12T08:18:42 Z somo Travelling Merchant (CCO21_day2problem1) C++14
25 / 25
526 ms 96832 KB
#include<bits/stdc++.h>
#define ll long long
#define pii pair<ll,ll>
#define F first
#define S second
using namespace std;

const int N = 200005;

ll n;
ll m;
ll in[N][4], out[N];
unordered_set<ll>f[N],b[N];
bool vis[N];
queue<ll>q;
priority_queue<pii>pq;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    memset(vis,false,sizeof(vis));
    cin >> n >> m;
    for(ll i=1;i<=m;i++){
        ll x,y,z,w;
        cin >> x >> y >> z >> w;
        in[i][0] = x;
        in[i][1] = y;
        in[i][2] = z;
        in[i][3] = w;
        f[x].insert(i);
        b[y].insert(i);
    }
    for(ll i=1;i<=n;i++){
        if(f[i].size() == 0){
            q.push(i);
        }
    }
    while(!q.empty()){
        int cur = q.front();
        q.pop();
        out[cur] = -1;
        for(auto &i : b[cur]){
            if(vis[i]) continue;
            vis[i] = 1;
            f[in[i][0]].erase(f[in[i][0]].find(i));
            if(f[in[i][0]].size() == 0) q.push(in[i][0]);
        }
    }
    for(ll i=1;i<=m;i++){
        if(!vis[i]){
            pq.push({in[i][2] , i});
        }
    }
    while(!pq.empty()){
        pii cur = pq.top();
        pq.pop();
        if(vis[cur.S]) continue;
        vis[cur.S] = 1;
        f[in[cur.S][0]].erase(f[in[cur.S][0]].find(cur.S));
        b[in[cur.S][1]].erase(b[in[cur.S][1]].find(cur.S));
        if(f[in[cur.S][0]].empty()){
            for(auto &i : b[in[cur.S][0]]){
                if(!vis[i]){
                    if(cur.F - in[i][3] > in[i][2]) pq.push({cur.F-in[i][3],i});
                }
            }
            out[in[cur.S][0]] = cur.F;
        }
    }
    for(ll i=1;i<n;i++) cout << out[i] << ' ';
    cout << out[n] << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 22860 KB Output is correct
2 Correct 16 ms 22956 KB Output is correct
3 Correct 14 ms 22684 KB Output is correct
4 Correct 15 ms 22832 KB Output is correct
5 Correct 14 ms 22860 KB Output is correct
6 Correct 15 ms 22860 KB Output is correct
7 Correct 14 ms 22680 KB Output is correct
8 Correct 18 ms 23224 KB Output is correct
9 Correct 16 ms 23096 KB Output is correct
10 Correct 14 ms 22648 KB Output is correct
11 Correct 14 ms 22820 KB Output is correct
12 Correct 14 ms 22708 KB Output is correct
13 Correct 13 ms 22704 KB Output is correct
14 Correct 15 ms 23216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 432 ms 71876 KB Output is correct
2 Correct 431 ms 76692 KB Output is correct
3 Correct 385 ms 54388 KB Output is correct
4 Correct 43 ms 27844 KB Output is correct
5 Correct 439 ms 72712 KB Output is correct
6 Correct 445 ms 72820 KB Output is correct
7 Correct 398 ms 53564 KB Output is correct
8 Correct 485 ms 96676 KB Output is correct
9 Correct 499 ms 87084 KB Output is correct
10 Correct 331 ms 51892 KB Output is correct
11 Correct 446 ms 68844 KB Output is correct
12 Correct 287 ms 50552 KB Output is correct
13 Correct 213 ms 53292 KB Output is correct
14 Correct 481 ms 96668 KB Output is correct
15 Correct 485 ms 96652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 22860 KB Output is correct
2 Correct 16 ms 22956 KB Output is correct
3 Correct 14 ms 22684 KB Output is correct
4 Correct 15 ms 22832 KB Output is correct
5 Correct 14 ms 22860 KB Output is correct
6 Correct 15 ms 22860 KB Output is correct
7 Correct 14 ms 22680 KB Output is correct
8 Correct 18 ms 23224 KB Output is correct
9 Correct 16 ms 23096 KB Output is correct
10 Correct 14 ms 22648 KB Output is correct
11 Correct 14 ms 22820 KB Output is correct
12 Correct 14 ms 22708 KB Output is correct
13 Correct 13 ms 22704 KB Output is correct
14 Correct 15 ms 23216 KB Output is correct
15 Correct 432 ms 71876 KB Output is correct
16 Correct 431 ms 76692 KB Output is correct
17 Correct 385 ms 54388 KB Output is correct
18 Correct 43 ms 27844 KB Output is correct
19 Correct 439 ms 72712 KB Output is correct
20 Correct 445 ms 72820 KB Output is correct
21 Correct 398 ms 53564 KB Output is correct
22 Correct 485 ms 96676 KB Output is correct
23 Correct 499 ms 87084 KB Output is correct
24 Correct 331 ms 51892 KB Output is correct
25 Correct 446 ms 68844 KB Output is correct
26 Correct 287 ms 50552 KB Output is correct
27 Correct 213 ms 53292 KB Output is correct
28 Correct 481 ms 96668 KB Output is correct
29 Correct 485 ms 96652 KB Output is correct
30 Correct 424 ms 76448 KB Output is correct
31 Correct 428 ms 76492 KB Output is correct
32 Correct 377 ms 53300 KB Output is correct
33 Correct 40 ms 27812 KB Output is correct
34 Correct 446 ms 72716 KB Output is correct
35 Correct 450 ms 72948 KB Output is correct
36 Correct 374 ms 53392 KB Output is correct
37 Correct 472 ms 96652 KB Output is correct
38 Correct 526 ms 88128 KB Output is correct
39 Correct 332 ms 51884 KB Output is correct
40 Correct 457 ms 68764 KB Output is correct
41 Correct 253 ms 50448 KB Output is correct
42 Correct 206 ms 53260 KB Output is correct
43 Correct 479 ms 96684 KB Output is correct
44 Correct 485 ms 96644 KB Output is correct
45 Correct 473 ms 96832 KB Output is correct
46 Correct 368 ms 74592 KB Output is correct
47 Correct 384 ms 73324 KB Output is correct
48 Correct 365 ms 74020 KB Output is correct
49 Correct 395 ms 73988 KB Output is correct
50 Correct 12 ms 22348 KB Output is correct