답안 #1100330

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1100330 2024-10-13T14:13:19 Z MateiKing80 Graph (BOI20_graph) C++14
100 / 100
108 ms 23240 KB
#include <bits/stdc++.h>

using namespace std ;

const int NMAX = 1e5;

int arr[NMAX + 5];
int n, m;

vector<vector<pair<int, int>>> adj(NMAX + 5);

int vis[NMAX + 5];
int a[NMAX + 5], b[NMAX + 5];

int known = -1;
bool flag = true;

int ans[NMAX + 5];

vector<int>v;

void dfs(int node)
{
    vis[node] = 1;
    v.push_back(a[node] * (-1 * b[node]));
    for(auto &childd : adj[node])
    {
        int child = childd.first, w = childd.second;
        if(vis[child])
        {
            if(b[node] + b[child] != 0)
            {
                int x = (w - a[node] - a[child]) / (b[node] + b[child]);
                ans[node] = a[node] + x * b[node];
                known = node;
            }
            else if(a[node] + a[child] != w)
                flag = false;
            continue;
        }
        a[child] = w - a[node], b[child] = -1 * b[node];
        dfs(child);
    }
}

void dfs2(int node)
{
    vis[node] = 2;
    for(auto &childd : adj[node])
    {
        int child = childd.first, w = childd.second;
        if(vis[child] == 2)
        {
            if(ans[node] + ans[child] != w)
                flag = false;
            continue;
        }
        ans[child] = w - ans[node];
        dfs2(child);
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    for(int i = 0; i < m; i ++)
    {
        int x, y, z;
        cin >> x >> y >> z;
        z *= 2;
        adj[x].emplace_back(y, z);
        adj[y].emplace_back(x, z);
    }
    for(int i = 1; i <= n; i ++)
    {
        if(vis[i])
            continue;
        v.clear(), known = -1;
        b[i] = 1;
        dfs(i);
        if(!flag)
        {
            cout << "NO\n";
            return 0;

        }
        if(known == -1)
        {
            sort(v.begin(), v.end());
            ans[i] = v[v.size() / 2];
            known = i;
        }
        dfs2(known);
        if(!flag)
        {
            cout << "NO\n";
            return 0;
        }
    }
    cout << "YES\n";
    for(int i = 1; i <= n; i ++)
        cout << ans[i] / 2.00 << " ";
    cout << "\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB answer = YES
2 Correct 1 ms 2644 KB answer = YES
3 Correct 1 ms 2644 KB answer = YES
4 Correct 1 ms 2644 KB answer = NO
5 Correct 1 ms 2808 KB answer = YES
6 Correct 1 ms 2644 KB answer = YES
7 Correct 1 ms 2644 KB answer = YES
8 Correct 2 ms 2644 KB answer = YES
9 Correct 1 ms 2644 KB answer = NO
10 Correct 1 ms 2644 KB answer = YES
11 Correct 1 ms 2644 KB answer = YES
12 Correct 1 ms 2644 KB answer = NO
13 Correct 1 ms 2644 KB answer = YES
14 Correct 1 ms 2804 KB answer = YES
15 Correct 1 ms 2644 KB answer = YES
16 Correct 1 ms 2808 KB answer = YES
17 Correct 1 ms 2644 KB answer = YES
18 Correct 1 ms 2644 KB answer = YES
19 Correct 1 ms 2644 KB answer = YES
20 Correct 2 ms 2808 KB answer = YES
21 Correct 1 ms 2644 KB answer = YES
22 Correct 2 ms 2644 KB answer = NO
23 Correct 1 ms 2644 KB answer = NO
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB answer = YES
2 Correct 1 ms 2644 KB answer = YES
3 Correct 1 ms 2644 KB answer = YES
4 Correct 1 ms 2644 KB answer = NO
5 Correct 1 ms 2808 KB answer = YES
6 Correct 1 ms 2644 KB answer = YES
7 Correct 1 ms 2644 KB answer = YES
8 Correct 2 ms 2644 KB answer = YES
9 Correct 1 ms 2644 KB answer = NO
10 Correct 1 ms 2644 KB answer = YES
11 Correct 1 ms 2644 KB answer = YES
12 Correct 1 ms 2644 KB answer = NO
13 Correct 1 ms 2644 KB answer = YES
14 Correct 1 ms 2804 KB answer = YES
15 Correct 1 ms 2644 KB answer = YES
16 Correct 1 ms 2808 KB answer = YES
17 Correct 1 ms 2644 KB answer = YES
18 Correct 1 ms 2644 KB answer = YES
19 Correct 1 ms 2644 KB answer = YES
20 Correct 2 ms 2808 KB answer = YES
21 Correct 1 ms 2644 KB answer = YES
22 Correct 2 ms 2644 KB answer = NO
23 Correct 1 ms 2644 KB answer = NO
24 Correct 1 ms 2644 KB answer = YES
25 Correct 2 ms 2644 KB answer = YES
26 Correct 1 ms 2644 KB answer = YES
27 Correct 1 ms 2644 KB answer = YES
28 Correct 1 ms 2644 KB answer = YES
29 Correct 1 ms 2644 KB answer = YES
30 Correct 1 ms 2808 KB answer = NO
31 Correct 2 ms 2644 KB answer = YES
32 Correct 1 ms 2644 KB answer = YES
33 Correct 2 ms 2720 KB answer = YES
34 Correct 2 ms 2644 KB answer = YES
35 Correct 1 ms 2644 KB answer = YES
36 Correct 1 ms 2644 KB answer = YES
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB answer = YES
2 Correct 1 ms 2644 KB answer = YES
3 Correct 1 ms 2644 KB answer = YES
4 Correct 1 ms 2644 KB answer = NO
5 Correct 1 ms 2808 KB answer = YES
6 Correct 1 ms 2644 KB answer = YES
7 Correct 1 ms 2644 KB answer = YES
8 Correct 2 ms 2644 KB answer = YES
9 Correct 1 ms 2644 KB answer = NO
10 Correct 1 ms 2644 KB answer = YES
11 Correct 1 ms 2644 KB answer = YES
12 Correct 1 ms 2644 KB answer = NO
13 Correct 1 ms 2644 KB answer = YES
14 Correct 1 ms 2804 KB answer = YES
15 Correct 1 ms 2644 KB answer = YES
16 Correct 1 ms 2808 KB answer = YES
17 Correct 1 ms 2644 KB answer = YES
18 Correct 1 ms 2644 KB answer = YES
19 Correct 1 ms 2644 KB answer = YES
20 Correct 2 ms 2808 KB answer = YES
21 Correct 1 ms 2644 KB answer = YES
22 Correct 2 ms 2644 KB answer = NO
23 Correct 1 ms 2644 KB answer = NO
24 Correct 1 ms 2644 KB answer = YES
25 Correct 2 ms 2644 KB answer = YES
26 Correct 1 ms 2644 KB answer = YES
27 Correct 1 ms 2644 KB answer = YES
28 Correct 1 ms 2644 KB answer = YES
29 Correct 1 ms 2644 KB answer = YES
30 Correct 1 ms 2808 KB answer = NO
31 Correct 2 ms 2644 KB answer = YES
32 Correct 1 ms 2644 KB answer = YES
33 Correct 2 ms 2720 KB answer = YES
34 Correct 2 ms 2644 KB answer = YES
35 Correct 1 ms 2644 KB answer = YES
36 Correct 1 ms 2644 KB answer = YES
37 Correct 2 ms 2808 KB answer = YES
38 Correct 1 ms 2748 KB answer = YES
39 Correct 2 ms 2644 KB answer = YES
40 Correct 1 ms 2900 KB answer = YES
41 Correct 2 ms 2900 KB answer = NO
42 Correct 2 ms 2900 KB answer = YES
43 Correct 2 ms 2900 KB answer = YES
44 Correct 2 ms 2900 KB answer = YES
45 Correct 2 ms 2900 KB answer = YES
46 Correct 2 ms 2644 KB answer = YES
47 Correct 2 ms 2900 KB answer = YES
48 Correct 2 ms 2900 KB answer = YES
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB answer = YES
2 Correct 1 ms 2644 KB answer = YES
3 Correct 1 ms 2644 KB answer = YES
4 Correct 1 ms 2644 KB answer = NO
5 Correct 1 ms 2808 KB answer = YES
6 Correct 1 ms 2644 KB answer = YES
7 Correct 1 ms 2644 KB answer = YES
8 Correct 2 ms 2644 KB answer = YES
9 Correct 1 ms 2644 KB answer = NO
10 Correct 1 ms 2644 KB answer = YES
11 Correct 1 ms 2644 KB answer = YES
12 Correct 1 ms 2644 KB answer = NO
13 Correct 1 ms 2644 KB answer = YES
14 Correct 1 ms 2804 KB answer = YES
15 Correct 1 ms 2644 KB answer = YES
16 Correct 1 ms 2808 KB answer = YES
17 Correct 1 ms 2644 KB answer = YES
18 Correct 1 ms 2644 KB answer = YES
19 Correct 1 ms 2644 KB answer = YES
20 Correct 2 ms 2808 KB answer = YES
21 Correct 1 ms 2644 KB answer = YES
22 Correct 2 ms 2644 KB answer = NO
23 Correct 1 ms 2644 KB answer = NO
24 Correct 1 ms 2644 KB answer = YES
25 Correct 2 ms 2644 KB answer = YES
26 Correct 1 ms 2644 KB answer = YES
27 Correct 1 ms 2644 KB answer = YES
28 Correct 1 ms 2644 KB answer = YES
29 Correct 1 ms 2644 KB answer = YES
30 Correct 1 ms 2808 KB answer = NO
31 Correct 2 ms 2644 KB answer = YES
32 Correct 1 ms 2644 KB answer = YES
33 Correct 2 ms 2720 KB answer = YES
34 Correct 2 ms 2644 KB answer = YES
35 Correct 1 ms 2644 KB answer = YES
36 Correct 1 ms 2644 KB answer = YES
37 Correct 2 ms 2808 KB answer = YES
38 Correct 1 ms 2748 KB answer = YES
39 Correct 2 ms 2644 KB answer = YES
40 Correct 1 ms 2900 KB answer = YES
41 Correct 2 ms 2900 KB answer = NO
42 Correct 2 ms 2900 KB answer = YES
43 Correct 2 ms 2900 KB answer = YES
44 Correct 2 ms 2900 KB answer = YES
45 Correct 2 ms 2900 KB answer = YES
46 Correct 2 ms 2644 KB answer = YES
47 Correct 2 ms 2900 KB answer = YES
48 Correct 2 ms 2900 KB answer = YES
49 Correct 7 ms 3412 KB answer = YES
50 Correct 7 ms 3924 KB answer = YES
51 Correct 7 ms 4064 KB answer = YES
52 Correct 4 ms 4088 KB answer = NO
53 Correct 2 ms 2900 KB answer = YES
54 Correct 3 ms 2900 KB answer = YES
55 Correct 4 ms 3156 KB answer = YES
56 Correct 6 ms 3412 KB answer = YES
57 Correct 10 ms 3424 KB answer = YES
58 Correct 7 ms 3412 KB answer = YES
59 Correct 8 ms 3412 KB answer = YES
60 Correct 7 ms 3500 KB answer = YES
61 Correct 4 ms 3156 KB answer = YES
62 Correct 43 ms 10488 KB answer = NO
63 Correct 45 ms 10484 KB answer = YES
64 Correct 47 ms 10512 KB answer = NO
65 Correct 51 ms 10692 KB answer = YES
66 Correct 2 ms 2900 KB answer = YES
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB answer = YES
2 Correct 1 ms 2644 KB answer = YES
3 Correct 1 ms 2644 KB answer = YES
4 Correct 1 ms 2644 KB answer = NO
5 Correct 1 ms 2808 KB answer = YES
6 Correct 1 ms 2644 KB answer = YES
7 Correct 1 ms 2644 KB answer = YES
8 Correct 2 ms 2644 KB answer = YES
9 Correct 1 ms 2644 KB answer = NO
10 Correct 1 ms 2644 KB answer = YES
11 Correct 1 ms 2644 KB answer = YES
12 Correct 1 ms 2644 KB answer = NO
13 Correct 1 ms 2644 KB answer = YES
14 Correct 1 ms 2804 KB answer = YES
15 Correct 1 ms 2644 KB answer = YES
16 Correct 1 ms 2808 KB answer = YES
17 Correct 1 ms 2644 KB answer = YES
18 Correct 1 ms 2644 KB answer = YES
19 Correct 1 ms 2644 KB answer = YES
20 Correct 2 ms 2808 KB answer = YES
21 Correct 1 ms 2644 KB answer = YES
22 Correct 2 ms 2644 KB answer = NO
23 Correct 1 ms 2644 KB answer = NO
24 Correct 1 ms 2644 KB answer = YES
25 Correct 2 ms 2644 KB answer = YES
26 Correct 1 ms 2644 KB answer = YES
27 Correct 1 ms 2644 KB answer = YES
28 Correct 1 ms 2644 KB answer = YES
29 Correct 1 ms 2644 KB answer = YES
30 Correct 1 ms 2808 KB answer = NO
31 Correct 2 ms 2644 KB answer = YES
32 Correct 1 ms 2644 KB answer = YES
33 Correct 2 ms 2720 KB answer = YES
34 Correct 2 ms 2644 KB answer = YES
35 Correct 1 ms 2644 KB answer = YES
36 Correct 1 ms 2644 KB answer = YES
37 Correct 2 ms 2808 KB answer = YES
38 Correct 1 ms 2748 KB answer = YES
39 Correct 2 ms 2644 KB answer = YES
40 Correct 1 ms 2900 KB answer = YES
41 Correct 2 ms 2900 KB answer = NO
42 Correct 2 ms 2900 KB answer = YES
43 Correct 2 ms 2900 KB answer = YES
44 Correct 2 ms 2900 KB answer = YES
45 Correct 2 ms 2900 KB answer = YES
46 Correct 2 ms 2644 KB answer = YES
47 Correct 2 ms 2900 KB answer = YES
48 Correct 2 ms 2900 KB answer = YES
49 Correct 7 ms 3412 KB answer = YES
50 Correct 7 ms 3924 KB answer = YES
51 Correct 7 ms 4064 KB answer = YES
52 Correct 4 ms 4088 KB answer = NO
53 Correct 2 ms 2900 KB answer = YES
54 Correct 3 ms 2900 KB answer = YES
55 Correct 4 ms 3156 KB answer = YES
56 Correct 6 ms 3412 KB answer = YES
57 Correct 10 ms 3424 KB answer = YES
58 Correct 7 ms 3412 KB answer = YES
59 Correct 8 ms 3412 KB answer = YES
60 Correct 7 ms 3500 KB answer = YES
61 Correct 4 ms 3156 KB answer = YES
62 Correct 43 ms 10488 KB answer = NO
63 Correct 45 ms 10484 KB answer = YES
64 Correct 47 ms 10512 KB answer = NO
65 Correct 51 ms 10692 KB answer = YES
66 Correct 2 ms 2900 KB answer = YES
67 Correct 62 ms 18944 KB answer = YES
68 Correct 55 ms 18884 KB answer = YES
69 Correct 62 ms 18960 KB answer = YES
70 Correct 75 ms 23240 KB answer = YES
71 Correct 57 ms 19140 KB answer = YES
72 Correct 54 ms 10180 KB answer = YES
73 Correct 52 ms 10132 KB answer = YES
74 Correct 41 ms 11984 KB answer = YES
75 Correct 21 ms 11472 KB answer = NO
76 Correct 7 ms 3668 KB answer = YES
77 Correct 14 ms 4692 KB answer = YES
78 Correct 24 ms 5848 KB answer = YES
79 Correct 47 ms 8916 KB answer = YES
80 Correct 50 ms 11976 KB answer = YES
81 Correct 34 ms 13768 KB answer = NO
82 Correct 73 ms 18372 KB answer = YES
83 Correct 72 ms 19140 KB answer = YES
84 Correct 74 ms 18884 KB answer = YES
85 Correct 65 ms 18884 KB answer = YES
86 Correct 62 ms 18884 KB answer = YES
87 Correct 33 ms 11596 KB answer = NO
88 Correct 71 ms 13444 KB answer = YES
89 Correct 54 ms 8968 KB answer = YES
90 Correct 71 ms 9036 KB answer = YES
91 Correct 57 ms 9160 KB answer = YES
92 Correct 36 ms 6608 KB answer = YES
93 Correct 28 ms 6360 KB answer = YES
94 Correct 42 ms 18280 KB answer = NO
95 Correct 26 ms 8788 KB answer = NO
96 Correct 108 ms 19580 KB answer = YES
97 Correct 34 ms 18380 KB answer = NO