답안 #580086

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
580086 2022-06-20T14:46:13 Z jiahng Graph (BOI20_graph) C++14
34 / 100
53 ms 8144 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define int ll
typedef pair<int32_t, int32_t> pi;
typedef vector <int> vi;
typedef vector <pi> vpi;
typedef pair<pi, ll> pii;
typedef set <ll> si;
typedef long double ld;
#define f first
#define s second
#define mp make_pair
#define FOR(i,s,e) for(int i=s;i<=int(e);++i)
#define DEC(i,s,e) for(int i=s;i>=int(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define maxn 100010
#define INF (ll)1e9+10
#define MOD 1000000007
typedef pair <vi, int> pvi;
typedef pair <int,pi> ipi;
typedef vector <pii> vpii;
int N,M,a,b,c;
bool vis[maxn];
vpi adj[maxn];

ld value;
int status = 0; // status is 0 if not set, 1 if fixed and -1 if no solution
pi val[maxn];
vi v;
ld ans[maxn];
void dfs(int x){
    if (status == -1) return;
    vis[x] = 1;
    v.pb(x);
    aFOR(i,adj[x]){
        if (vis[i.f]){
           pi cur = val[x];
           cur.f += val[i.f].f;
           cur.s += val[i.f].s;
           if (cur.f == 0){
               if (cur.s != i.s){
                  status = -1; return;
               }
           }else{
               ld newvalue = (ld(i.s) - ld(cur.s)) / ld(cur.f);
               if (status == 1 && value != newvalue){
                   status = -1; return;
               }
               value = newvalue;
               status = 1;
           }
        }else{
            val[i.f] = pi(-val[x].f, i.s - val[x].s);
            dfs(i.f);
        }
    }
}
int32_t main(){
    fast;
    cin >> N >> M;
    FOR(i,1,M){
        cin >> a >> b >> c;
        adj[a].pb(pi(b, c)); adj[b].pb(pi(a,c));
    }
    FOR(i,1,N) if (!vis[i]){
        val[i] = pi(1,0);
        status = 0;
        v.clear();
        dfs(i);
        if (status == -1){
            cout << "NO"; return 0;
        }else if (status == 0){
            aFOR(j,v) aFOR(k,adj[j]) assert(val[j].f + val[k.f].f == 0);
            vi v2;
            aFOR(j,v){
                if (val[j].f == -1) v2.pb(val[j].s);
                else v2.pb(-val[j].s);
            }
            sort(all(v2));
            value = v2[v2.size()/2];
        }
        
        aFOR(j,v) ans[j] = (ld)val[j].f * value + (ld)val[j].s;
        //aFOR(j,v) aFOR(k,adj[j]) assert(ans[j] + ans[k.f] == k.s);
    }
    cout << "YES\n";
    FOR(i,1,N) cout << setprecision(10) << ans[i] << ' ';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB answer = YES
2 Correct 1 ms 2644 KB answer = YES
3 Correct 2 ms 2644 KB answer = YES
4 Correct 1 ms 2644 KB answer = NO
5 Correct 1 ms 2644 KB answer = YES
6 Correct 3 ms 2644 KB answer = YES
7 Correct 1 ms 2644 KB answer = YES
8 Correct 1 ms 2644 KB answer = YES
9 Correct 1 ms 2644 KB answer = NO
10 Correct 2 ms 2644 KB answer = YES
11 Correct 2 ms 2644 KB answer = YES
12 Correct 2 ms 2644 KB answer = NO
13 Correct 2 ms 2644 KB answer = YES
14 Correct 2 ms 2644 KB answer = YES
15 Correct 2 ms 2644 KB answer = YES
16 Correct 3 ms 2644 KB answer = YES
17 Correct 2 ms 2644 KB answer = YES
18 Correct 2 ms 2644 KB answer = YES
19 Correct 2 ms 2644 KB answer = YES
20 Correct 2 ms 2644 KB answer = YES
21 Correct 1 ms 2644 KB answer = YES
22 Correct 2 ms 2644 KB answer = NO
23 Correct 2 ms 2644 KB answer = NO
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB answer = YES
2 Correct 1 ms 2644 KB answer = YES
3 Correct 2 ms 2644 KB answer = YES
4 Correct 1 ms 2644 KB answer = NO
5 Correct 1 ms 2644 KB answer = YES
6 Correct 3 ms 2644 KB answer = YES
7 Correct 1 ms 2644 KB answer = YES
8 Correct 1 ms 2644 KB answer = YES
9 Correct 1 ms 2644 KB answer = NO
10 Correct 2 ms 2644 KB answer = YES
11 Correct 2 ms 2644 KB answer = YES
12 Correct 2 ms 2644 KB answer = NO
13 Correct 2 ms 2644 KB answer = YES
14 Correct 2 ms 2644 KB answer = YES
15 Correct 2 ms 2644 KB answer = YES
16 Correct 3 ms 2644 KB answer = YES
17 Correct 2 ms 2644 KB answer = YES
18 Correct 2 ms 2644 KB answer = YES
19 Correct 2 ms 2644 KB answer = YES
20 Correct 2 ms 2644 KB answer = YES
21 Correct 1 ms 2644 KB answer = YES
22 Correct 2 ms 2644 KB answer = NO
23 Correct 2 ms 2644 KB answer = NO
24 Correct 1 ms 2644 KB answer = YES
25 Correct 2 ms 2644 KB answer = YES
26 Correct 2 ms 2644 KB answer = YES
27 Correct 2 ms 2644 KB answer = YES
28 Correct 2 ms 2644 KB answer = YES
29 Correct 3 ms 2644 KB answer = YES
30 Correct 2 ms 2644 KB answer = NO
31 Correct 2 ms 2644 KB answer = YES
32 Correct 3 ms 2644 KB answer = YES
33 Correct 2 ms 2644 KB answer = YES
34 Correct 2 ms 2644 KB answer = YES
35 Correct 2 ms 2644 KB answer = YES
36 Correct 2 ms 2644 KB answer = YES
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB answer = YES
2 Correct 1 ms 2644 KB answer = YES
3 Correct 2 ms 2644 KB answer = YES
4 Correct 1 ms 2644 KB answer = NO
5 Correct 1 ms 2644 KB answer = YES
6 Correct 3 ms 2644 KB answer = YES
7 Correct 1 ms 2644 KB answer = YES
8 Correct 1 ms 2644 KB answer = YES
9 Correct 1 ms 2644 KB answer = NO
10 Correct 2 ms 2644 KB answer = YES
11 Correct 2 ms 2644 KB answer = YES
12 Correct 2 ms 2644 KB answer = NO
13 Correct 2 ms 2644 KB answer = YES
14 Correct 2 ms 2644 KB answer = YES
15 Correct 2 ms 2644 KB answer = YES
16 Correct 3 ms 2644 KB answer = YES
17 Correct 2 ms 2644 KB answer = YES
18 Correct 2 ms 2644 KB answer = YES
19 Correct 2 ms 2644 KB answer = YES
20 Correct 2 ms 2644 KB answer = YES
21 Correct 1 ms 2644 KB answer = YES
22 Correct 2 ms 2644 KB answer = NO
23 Correct 2 ms 2644 KB answer = NO
24 Correct 1 ms 2644 KB answer = YES
25 Correct 2 ms 2644 KB answer = YES
26 Correct 2 ms 2644 KB answer = YES
27 Correct 2 ms 2644 KB answer = YES
28 Correct 2 ms 2644 KB answer = YES
29 Correct 3 ms 2644 KB answer = YES
30 Correct 2 ms 2644 KB answer = NO
31 Correct 2 ms 2644 KB answer = YES
32 Correct 3 ms 2644 KB answer = YES
33 Correct 2 ms 2644 KB answer = YES
34 Correct 2 ms 2644 KB answer = YES
35 Correct 2 ms 2644 KB answer = YES
36 Correct 2 ms 2644 KB answer = YES
37 Correct 2 ms 2644 KB answer = YES
38 Correct 2 ms 2644 KB answer = YES
39 Correct 2 ms 2644 KB answer = YES
40 Correct 2 ms 2772 KB answer = YES
41 Correct 2 ms 2644 KB answer = NO
42 Correct 2 ms 2772 KB answer = YES
43 Correct 3 ms 2644 KB answer = YES
44 Correct 2 ms 2644 KB answer = YES
45 Correct 2 ms 2644 KB answer = YES
46 Correct 2 ms 2644 KB answer = YES
47 Correct 2 ms 2772 KB answer = YES
48 Correct 2 ms 2772 KB answer = YES
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB answer = YES
2 Correct 1 ms 2644 KB answer = YES
3 Correct 2 ms 2644 KB answer = YES
4 Correct 1 ms 2644 KB answer = NO
5 Correct 1 ms 2644 KB answer = YES
6 Correct 3 ms 2644 KB answer = YES
7 Correct 1 ms 2644 KB answer = YES
8 Correct 1 ms 2644 KB answer = YES
9 Correct 1 ms 2644 KB answer = NO
10 Correct 2 ms 2644 KB answer = YES
11 Correct 2 ms 2644 KB answer = YES
12 Correct 2 ms 2644 KB answer = NO
13 Correct 2 ms 2644 KB answer = YES
14 Correct 2 ms 2644 KB answer = YES
15 Correct 2 ms 2644 KB answer = YES
16 Correct 3 ms 2644 KB answer = YES
17 Correct 2 ms 2644 KB answer = YES
18 Correct 2 ms 2644 KB answer = YES
19 Correct 2 ms 2644 KB answer = YES
20 Correct 2 ms 2644 KB answer = YES
21 Correct 1 ms 2644 KB answer = YES
22 Correct 2 ms 2644 KB answer = NO
23 Correct 2 ms 2644 KB answer = NO
24 Correct 1 ms 2644 KB answer = YES
25 Correct 2 ms 2644 KB answer = YES
26 Correct 2 ms 2644 KB answer = YES
27 Correct 2 ms 2644 KB answer = YES
28 Correct 2 ms 2644 KB answer = YES
29 Correct 3 ms 2644 KB answer = YES
30 Correct 2 ms 2644 KB answer = NO
31 Correct 2 ms 2644 KB answer = YES
32 Correct 3 ms 2644 KB answer = YES
33 Correct 2 ms 2644 KB answer = YES
34 Correct 2 ms 2644 KB answer = YES
35 Correct 2 ms 2644 KB answer = YES
36 Correct 2 ms 2644 KB answer = YES
37 Correct 2 ms 2644 KB answer = YES
38 Correct 2 ms 2644 KB answer = YES
39 Correct 2 ms 2644 KB answer = YES
40 Correct 2 ms 2772 KB answer = YES
41 Correct 2 ms 2644 KB answer = NO
42 Correct 2 ms 2772 KB answer = YES
43 Correct 3 ms 2644 KB answer = YES
44 Correct 2 ms 2644 KB answer = YES
45 Correct 2 ms 2644 KB answer = YES
46 Correct 2 ms 2644 KB answer = YES
47 Correct 2 ms 2772 KB answer = YES
48 Correct 2 ms 2772 KB answer = YES
49 Correct 10 ms 3460 KB answer = YES
50 Correct 13 ms 3796 KB answer = YES
51 Correct 12 ms 3716 KB answer = YES
52 Correct 5 ms 3156 KB answer = NO
53 Correct 2 ms 2772 KB answer = YES
54 Correct 4 ms 2900 KB answer = YES
55 Correct 6 ms 3028 KB answer = YES
56 Correct 9 ms 3460 KB answer = YES
57 Correct 11 ms 3400 KB answer = YES
58 Correct 9 ms 3396 KB answer = YES
59 Correct 10 ms 3364 KB answer = YES
60 Correct 11 ms 3496 KB answer = YES
61 Correct 6 ms 3028 KB answer = YES
62 Correct 50 ms 7640 KB answer = NO
63 Correct 53 ms 8120 KB answer = YES
64 Incorrect 53 ms 8144 KB Sum of endpoints for edge (7782; 2701) differs from the expected value 2.
65 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB answer = YES
2 Correct 1 ms 2644 KB answer = YES
3 Correct 2 ms 2644 KB answer = YES
4 Correct 1 ms 2644 KB answer = NO
5 Correct 1 ms 2644 KB answer = YES
6 Correct 3 ms 2644 KB answer = YES
7 Correct 1 ms 2644 KB answer = YES
8 Correct 1 ms 2644 KB answer = YES
9 Correct 1 ms 2644 KB answer = NO
10 Correct 2 ms 2644 KB answer = YES
11 Correct 2 ms 2644 KB answer = YES
12 Correct 2 ms 2644 KB answer = NO
13 Correct 2 ms 2644 KB answer = YES
14 Correct 2 ms 2644 KB answer = YES
15 Correct 2 ms 2644 KB answer = YES
16 Correct 3 ms 2644 KB answer = YES
17 Correct 2 ms 2644 KB answer = YES
18 Correct 2 ms 2644 KB answer = YES
19 Correct 2 ms 2644 KB answer = YES
20 Correct 2 ms 2644 KB answer = YES
21 Correct 1 ms 2644 KB answer = YES
22 Correct 2 ms 2644 KB answer = NO
23 Correct 2 ms 2644 KB answer = NO
24 Correct 1 ms 2644 KB answer = YES
25 Correct 2 ms 2644 KB answer = YES
26 Correct 2 ms 2644 KB answer = YES
27 Correct 2 ms 2644 KB answer = YES
28 Correct 2 ms 2644 KB answer = YES
29 Correct 3 ms 2644 KB answer = YES
30 Correct 2 ms 2644 KB answer = NO
31 Correct 2 ms 2644 KB answer = YES
32 Correct 3 ms 2644 KB answer = YES
33 Correct 2 ms 2644 KB answer = YES
34 Correct 2 ms 2644 KB answer = YES
35 Correct 2 ms 2644 KB answer = YES
36 Correct 2 ms 2644 KB answer = YES
37 Correct 2 ms 2644 KB answer = YES
38 Correct 2 ms 2644 KB answer = YES
39 Correct 2 ms 2644 KB answer = YES
40 Correct 2 ms 2772 KB answer = YES
41 Correct 2 ms 2644 KB answer = NO
42 Correct 2 ms 2772 KB answer = YES
43 Correct 3 ms 2644 KB answer = YES
44 Correct 2 ms 2644 KB answer = YES
45 Correct 2 ms 2644 KB answer = YES
46 Correct 2 ms 2644 KB answer = YES
47 Correct 2 ms 2772 KB answer = YES
48 Correct 2 ms 2772 KB answer = YES
49 Correct 10 ms 3460 KB answer = YES
50 Correct 13 ms 3796 KB answer = YES
51 Correct 12 ms 3716 KB answer = YES
52 Correct 5 ms 3156 KB answer = NO
53 Correct 2 ms 2772 KB answer = YES
54 Correct 4 ms 2900 KB answer = YES
55 Correct 6 ms 3028 KB answer = YES
56 Correct 9 ms 3460 KB answer = YES
57 Correct 11 ms 3400 KB answer = YES
58 Correct 9 ms 3396 KB answer = YES
59 Correct 10 ms 3364 KB answer = YES
60 Correct 11 ms 3496 KB answer = YES
61 Correct 6 ms 3028 KB answer = YES
62 Correct 50 ms 7640 KB answer = NO
63 Correct 53 ms 8120 KB answer = YES
64 Incorrect 53 ms 8144 KB Sum of endpoints for edge (7782; 2701) differs from the expected value 2.
65 Halted 0 ms 0 KB -