답안 #558357

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
558357 2022-05-07T07:23:37 Z hibiki Graph (BOI20_graph) C++11
0 / 100
2 ms 2656 KB
#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define F first
#define S second

int n,m;
int na[100005],nb[100005];
double x,ans[100005];
bool done[100005],found;
vector<int> has;
vector<pair<int,int> > v[100005];
map<pair<int,int>,int> mp;

void dfs(int nw, int fa)
{
    has.pb(nw);

    for(pair<int,int> go: v[nw])
    {
        if(go.F == fa) continue;

        int ga = na[nw] * -1, gb = go.S - nb[nw];

        if(!done[go.F])
        {
            done[go.F] = true;
            na[go.F] = ga;
            nb[go.F] = gb;
            dfs(go.F,nw);
        }
        else if(na[go.F] != ga)
        {
            double temp = (double)(nb[go.F] - gb) / (double)(ga - na[go.F]);
            if(found && temp != x)
            {
                printf("NO\n");
                exit(0);
            }
            x = temp;
            found = true;
        }
        else if(nb[go.F] != gb)
        {
            printf("NO\n");
            exit(0);
        }
    }
}

int main()
{
    scanf("%d %d",&n,&m);
    for(int i = 0; i < m; i++)
    {
        int a,b,c;
        scanf("%d %d %d",&a,&b,&c);
        if(!mp[{a,b}])
        {
            mp[{a,b}] = mp[{b,a}] = c;
            v[a].pb({b,c});
            v[b].pb({a,c});
        }
        else if(mp[{a,b}] != c)
        {
            printf("NO\n");
            return 0;
        }
    }

    for(int i = 1; i <= n; i++)
    {
        if(done[i]) continue;

        has.clear();
        found = false;

        done[i] = true;
        na[i] = 1;
        nb[i] = 0;
        dfs(i,i);

        if(!found)
        {
            vector<int> ss;
            for(int po: has)
                ss.pb(-na[po] * nb[po]);

            sort(ss.begin(),ss.end());

            x = (double)ss[ss.size() / 2];
        }

        for(int po: has)
            ans[po] = na[po] * x + nb[po];
    }

    printf("YES\n");
    for(int i = 1; i <= n; i++)
        printf("%lf ",ans[i]);
    printf("\n");

    return 0;
}

Compilation message

Graph.cpp: In function 'int main()':
Graph.cpp:54:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |     scanf("%d %d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~
Graph.cpp:58:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |         scanf("%d %d %d",&a,&b,&c);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB answer = YES
2 Correct 2 ms 2644 KB answer = YES
3 Correct 1 ms 2644 KB answer = YES
4 Correct 2 ms 2644 KB answer = NO
5 Correct 2 ms 2644 KB answer = YES
6 Correct 2 ms 2644 KB answer = YES
7 Correct 2 ms 2656 KB answer = YES
8 Correct 2 ms 2644 KB answer = YES
9 Correct 2 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 2 ms 2644 KB answer = YES
17 Correct 2 ms 2644 KB answer = YES
18 Incorrect 2 ms 2644 KB Sum of endpoints for edge (1; 1) differs from the expected value 1.
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB answer = YES
2 Correct 2 ms 2644 KB answer = YES
3 Correct 1 ms 2644 KB answer = YES
4 Correct 2 ms 2644 KB answer = NO
5 Correct 2 ms 2644 KB answer = YES
6 Correct 2 ms 2644 KB answer = YES
7 Correct 2 ms 2656 KB answer = YES
8 Correct 2 ms 2644 KB answer = YES
9 Correct 2 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 2 ms 2644 KB answer = YES
17 Correct 2 ms 2644 KB answer = YES
18 Incorrect 2 ms 2644 KB Sum of endpoints for edge (1; 1) differs from the expected value 1.
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB answer = YES
2 Correct 2 ms 2644 KB answer = YES
3 Correct 1 ms 2644 KB answer = YES
4 Correct 2 ms 2644 KB answer = NO
5 Correct 2 ms 2644 KB answer = YES
6 Correct 2 ms 2644 KB answer = YES
7 Correct 2 ms 2656 KB answer = YES
8 Correct 2 ms 2644 KB answer = YES
9 Correct 2 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 2 ms 2644 KB answer = YES
17 Correct 2 ms 2644 KB answer = YES
18 Incorrect 2 ms 2644 KB Sum of endpoints for edge (1; 1) differs from the expected value 1.
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB answer = YES
2 Correct 2 ms 2644 KB answer = YES
3 Correct 1 ms 2644 KB answer = YES
4 Correct 2 ms 2644 KB answer = NO
5 Correct 2 ms 2644 KB answer = YES
6 Correct 2 ms 2644 KB answer = YES
7 Correct 2 ms 2656 KB answer = YES
8 Correct 2 ms 2644 KB answer = YES
9 Correct 2 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 2 ms 2644 KB answer = YES
17 Correct 2 ms 2644 KB answer = YES
18 Incorrect 2 ms 2644 KB Sum of endpoints for edge (1; 1) differs from the expected value 1.
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB answer = YES
2 Correct 2 ms 2644 KB answer = YES
3 Correct 1 ms 2644 KB answer = YES
4 Correct 2 ms 2644 KB answer = NO
5 Correct 2 ms 2644 KB answer = YES
6 Correct 2 ms 2644 KB answer = YES
7 Correct 2 ms 2656 KB answer = YES
8 Correct 2 ms 2644 KB answer = YES
9 Correct 2 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 2 ms 2644 KB answer = YES
17 Correct 2 ms 2644 KB answer = YES
18 Incorrect 2 ms 2644 KB Sum of endpoints for edge (1; 1) differs from the expected value 1.
19 Halted 0 ms 0 KB -