답안 #1030591

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1030591 2024-07-22T07:15:35 Z sleepntsheep Graph (BOI20_graph) C++17
58 / 100
700 ms 18892 KB
#include<stdio.h>
#include<stdlib.h>
#include<vector>
#define N 100001
#define M 400001
double a(double x){return x<0?-x:x;}
int n,m,head[N],fr[M],to[M],nxt[M],col[M],ii,vis[N],aa[N],bb[N],grp[N],got[N];
double xx[N];
std::vector<int> A[N];

void link(int u,int v,int c){
    int i=++ii;
    to[i]=v;
    fr[i]=u;
    col[i]=c;
    nxt[i]=head[u];
    head[u]=i;
}

void dfs(int u,int a,int b,int cp){
    if(vis[u]){
        if(a==aa[u]&&b!=bb[u])
            exit(puts("NO")*0);
        return;
    }
    grp[u]=cp;
    A[cp].push_back(u);
    vis[u]=1,aa[u]=a,bb[u]=b;
    for(int j=head[u];j;j=nxt[j])
        dfs(to[j],-a,col[j]-b,cp);
}

int main(){
    scanf("%d%d",&n,&m);
    for(int u,v,c,i=0;i<m;++i)scanf("%d%d%d",&u,&v,&c),link(u,v,c),link(v,u,c);
    for(int i=1;i<=n;++i)
        if(!vis[i])
            dfs(i,1,0,i);

    for(int j=1;j<ii;++j){
        double a1=aa[fr[j]]+aa[to[j]],b1=bb[fr[j]]+bb[to[j]];
        int gp=grp[fr[j]];
        if(got[gp])continue;
        if(a1==0&&b1!=col[j])exit(puts("NO")*0);
        if(b1==col[j]&&a1==0)continue;
        int ok=1;
        double x = (col[j]-b1)/a1;
        for(int k=1;k<ii&&ok;++k){
            if(grp[fr[k]]!=gp)continue;
            if(aa[fr[k]]*x+bb[fr[k]]+aa[to[k]]*x+bb[to[k]] != col[k])ok=0;
        }
        if(ok)
            xx[gp]=x,got[gp]=1;
    }
    for(int i=1;i<=n;++i){
        if(got[grp[i]])continue;
        double min=1e18,argmin=424242;
        for(double f=-10000;f<=10000;f+=0.5){
            double sum=0;
            for(int j:A[grp[i]])sum+=a(aa[j]*f+bb[j]);
            if(min>sum) min=sum,argmin=f;
        }
        got[i]=1;xx[grp[i]]=argmin;
    }
    puts("YES");
    for(int i=1;i<=n;++i) printf("%.3f ",aa[i]*xx[grp[i]]+bb[i]);
}

Compilation message

Graph.cpp: In function 'int main()':
Graph.cpp:34:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |     scanf("%d%d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~
Graph.cpp:35:36: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |     for(int u,v,c,i=0;i<m;++i)scanf("%d%d%d",&u,&v,&c),link(u,v,c),link(v,u,c);
      |                               ~~~~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 9560 KB answer = YES
2 Correct 1 ms 9564 KB answer = YES
3 Correct 1 ms 9576 KB answer = YES
4 Correct 1 ms 7516 KB answer = NO
5 Correct 1 ms 7516 KB answer = YES
6 Correct 1 ms 7516 KB answer = YES
7 Correct 1 ms 7516 KB answer = YES
8 Correct 1 ms 7516 KB answer = YES
9 Correct 2 ms 7516 KB answer = NO
10 Correct 1 ms 7768 KB answer = YES
11 Correct 2 ms 7512 KB answer = YES
12 Correct 2 ms 9560 KB answer = NO
13 Correct 1 ms 7516 KB answer = YES
14 Correct 1 ms 7516 KB answer = YES
15 Correct 1 ms 9564 KB answer = YES
16 Correct 1 ms 7516 KB answer = YES
17 Correct 1 ms 3420 KB answer = YES
18 Correct 1 ms 3420 KB answer = YES
19 Correct 1 ms 3540 KB answer = YES
20 Correct 1 ms 5464 KB answer = YES
21 Correct 1 ms 3420 KB answer = YES
22 Correct 1 ms 5468 KB answer = NO
23 Correct 1 ms 5468 KB answer = NO
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 9560 KB answer = YES
2 Correct 1 ms 9564 KB answer = YES
3 Correct 1 ms 9576 KB answer = YES
4 Correct 1 ms 7516 KB answer = NO
5 Correct 1 ms 7516 KB answer = YES
6 Correct 1 ms 7516 KB answer = YES
7 Correct 1 ms 7516 KB answer = YES
8 Correct 1 ms 7516 KB answer = YES
9 Correct 2 ms 7516 KB answer = NO
10 Correct 1 ms 7768 KB answer = YES
11 Correct 2 ms 7512 KB answer = YES
12 Correct 2 ms 9560 KB answer = NO
13 Correct 1 ms 7516 KB answer = YES
14 Correct 1 ms 7516 KB answer = YES
15 Correct 1 ms 9564 KB answer = YES
16 Correct 1 ms 7516 KB answer = YES
17 Correct 1 ms 3420 KB answer = YES
18 Correct 1 ms 3420 KB answer = YES
19 Correct 1 ms 3540 KB answer = YES
20 Correct 1 ms 5464 KB answer = YES
21 Correct 1 ms 3420 KB answer = YES
22 Correct 1 ms 5468 KB answer = NO
23 Correct 1 ms 5468 KB answer = NO
24 Correct 5 ms 3420 KB answer = YES
25 Correct 4 ms 3420 KB answer = YES
26 Correct 5 ms 5468 KB answer = YES
27 Correct 1 ms 5468 KB answer = YES
28 Correct 1 ms 3420 KB answer = YES
29 Correct 5 ms 5540 KB answer = YES
30 Correct 1 ms 5464 KB answer = NO
31 Correct 2 ms 5468 KB answer = YES
32 Correct 1 ms 3504 KB answer = YES
33 Correct 5 ms 5556 KB answer = YES
34 Correct 2 ms 3420 KB answer = YES
35 Correct 1 ms 3420 KB answer = YES
36 Correct 1 ms 5468 KB answer = YES
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 9560 KB answer = YES
2 Correct 1 ms 9564 KB answer = YES
3 Correct 1 ms 9576 KB answer = YES
4 Correct 1 ms 7516 KB answer = NO
5 Correct 1 ms 7516 KB answer = YES
6 Correct 1 ms 7516 KB answer = YES
7 Correct 1 ms 7516 KB answer = YES
8 Correct 1 ms 7516 KB answer = YES
9 Correct 2 ms 7516 KB answer = NO
10 Correct 1 ms 7768 KB answer = YES
11 Correct 2 ms 7512 KB answer = YES
12 Correct 2 ms 9560 KB answer = NO
13 Correct 1 ms 7516 KB answer = YES
14 Correct 1 ms 7516 KB answer = YES
15 Correct 1 ms 9564 KB answer = YES
16 Correct 1 ms 7516 KB answer = YES
17 Correct 1 ms 3420 KB answer = YES
18 Correct 1 ms 3420 KB answer = YES
19 Correct 1 ms 3540 KB answer = YES
20 Correct 1 ms 5464 KB answer = YES
21 Correct 1 ms 3420 KB answer = YES
22 Correct 1 ms 5468 KB answer = NO
23 Correct 1 ms 5468 KB answer = NO
24 Correct 5 ms 3420 KB answer = YES
25 Correct 4 ms 3420 KB answer = YES
26 Correct 5 ms 5468 KB answer = YES
27 Correct 1 ms 5468 KB answer = YES
28 Correct 1 ms 3420 KB answer = YES
29 Correct 5 ms 5540 KB answer = YES
30 Correct 1 ms 5464 KB answer = NO
31 Correct 2 ms 5468 KB answer = YES
32 Correct 1 ms 3504 KB answer = YES
33 Correct 5 ms 5556 KB answer = YES
34 Correct 2 ms 3420 KB answer = YES
35 Correct 1 ms 3420 KB answer = YES
36 Correct 1 ms 5468 KB answer = YES
37 Correct 10 ms 5464 KB answer = YES
38 Correct 2 ms 3504 KB answer = YES
39 Correct 23 ms 5624 KB answer = YES
40 Correct 2 ms 3416 KB answer = YES
41 Correct 1 ms 3420 KB answer = NO
42 Correct 40 ms 5656 KB answer = YES
43 Correct 44 ms 5468 KB answer = YES
44 Correct 42 ms 7516 KB answer = YES
45 Correct 1 ms 3416 KB answer = YES
46 Correct 21 ms 5464 KB answer = YES
47 Correct 2 ms 5464 KB answer = YES
48 Correct 1 ms 5464 KB answer = YES
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 9560 KB answer = YES
2 Correct 1 ms 9564 KB answer = YES
3 Correct 1 ms 9576 KB answer = YES
4 Correct 1 ms 7516 KB answer = NO
5 Correct 1 ms 7516 KB answer = YES
6 Correct 1 ms 7516 KB answer = YES
7 Correct 1 ms 7516 KB answer = YES
8 Correct 1 ms 7516 KB answer = YES
9 Correct 2 ms 7516 KB answer = NO
10 Correct 1 ms 7768 KB answer = YES
11 Correct 2 ms 7512 KB answer = YES
12 Correct 2 ms 9560 KB answer = NO
13 Correct 1 ms 7516 KB answer = YES
14 Correct 1 ms 7516 KB answer = YES
15 Correct 1 ms 9564 KB answer = YES
16 Correct 1 ms 7516 KB answer = YES
17 Correct 1 ms 3420 KB answer = YES
18 Correct 1 ms 3420 KB answer = YES
19 Correct 1 ms 3540 KB answer = YES
20 Correct 1 ms 5464 KB answer = YES
21 Correct 1 ms 3420 KB answer = YES
22 Correct 1 ms 5468 KB answer = NO
23 Correct 1 ms 5468 KB answer = NO
24 Correct 5 ms 3420 KB answer = YES
25 Correct 4 ms 3420 KB answer = YES
26 Correct 5 ms 5468 KB answer = YES
27 Correct 1 ms 5468 KB answer = YES
28 Correct 1 ms 3420 KB answer = YES
29 Correct 5 ms 5540 KB answer = YES
30 Correct 1 ms 5464 KB answer = NO
31 Correct 2 ms 5468 KB answer = YES
32 Correct 1 ms 3504 KB answer = YES
33 Correct 5 ms 5556 KB answer = YES
34 Correct 2 ms 3420 KB answer = YES
35 Correct 1 ms 3420 KB answer = YES
36 Correct 1 ms 5468 KB answer = YES
37 Correct 10 ms 5464 KB answer = YES
38 Correct 2 ms 3504 KB answer = YES
39 Correct 23 ms 5624 KB answer = YES
40 Correct 2 ms 3416 KB answer = YES
41 Correct 1 ms 3420 KB answer = NO
42 Correct 40 ms 5656 KB answer = YES
43 Correct 44 ms 5468 KB answer = YES
44 Correct 42 ms 7516 KB answer = YES
45 Correct 1 ms 3416 KB answer = YES
46 Correct 21 ms 5464 KB answer = YES
47 Correct 2 ms 5464 KB answer = YES
48 Correct 1 ms 5464 KB answer = YES
49 Correct 433 ms 4188 KB answer = YES
50 Correct 6 ms 6588 KB answer = YES
51 Correct 404 ms 4704 KB answer = YES
52 Correct 3 ms 4700 KB answer = NO
53 Correct 41 ms 5468 KB answer = YES
54 Correct 95 ms 5736 KB answer = YES
55 Correct 204 ms 3932 KB answer = YES
56 Correct 415 ms 6212 KB answer = YES
57 Correct 430 ms 4184 KB answer = YES
58 Correct 358 ms 5980 KB answer = YES
59 Correct 5 ms 4184 KB answer = YES
60 Correct 424 ms 4188 KB answer = YES
61 Correct 3 ms 5720 KB answer = YES
62 Correct 30 ms 11404 KB answer = NO
63 Correct 41 ms 12020 KB answer = YES
64 Correct 31 ms 11856 KB answer = NO
65 Correct 42 ms 11912 KB answer = YES
66 Correct 80 ms 5720 KB answer = YES
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 9560 KB answer = YES
2 Correct 1 ms 9564 KB answer = YES
3 Correct 1 ms 9576 KB answer = YES
4 Correct 1 ms 7516 KB answer = NO
5 Correct 1 ms 7516 KB answer = YES
6 Correct 1 ms 7516 KB answer = YES
7 Correct 1 ms 7516 KB answer = YES
8 Correct 1 ms 7516 KB answer = YES
9 Correct 2 ms 7516 KB answer = NO
10 Correct 1 ms 7768 KB answer = YES
11 Correct 2 ms 7512 KB answer = YES
12 Correct 2 ms 9560 KB answer = NO
13 Correct 1 ms 7516 KB answer = YES
14 Correct 1 ms 7516 KB answer = YES
15 Correct 1 ms 9564 KB answer = YES
16 Correct 1 ms 7516 KB answer = YES
17 Correct 1 ms 3420 KB answer = YES
18 Correct 1 ms 3420 KB answer = YES
19 Correct 1 ms 3540 KB answer = YES
20 Correct 1 ms 5464 KB answer = YES
21 Correct 1 ms 3420 KB answer = YES
22 Correct 1 ms 5468 KB answer = NO
23 Correct 1 ms 5468 KB answer = NO
24 Correct 5 ms 3420 KB answer = YES
25 Correct 4 ms 3420 KB answer = YES
26 Correct 5 ms 5468 KB answer = YES
27 Correct 1 ms 5468 KB answer = YES
28 Correct 1 ms 3420 KB answer = YES
29 Correct 5 ms 5540 KB answer = YES
30 Correct 1 ms 5464 KB answer = NO
31 Correct 2 ms 5468 KB answer = YES
32 Correct 1 ms 3504 KB answer = YES
33 Correct 5 ms 5556 KB answer = YES
34 Correct 2 ms 3420 KB answer = YES
35 Correct 1 ms 3420 KB answer = YES
36 Correct 1 ms 5468 KB answer = YES
37 Correct 10 ms 5464 KB answer = YES
38 Correct 2 ms 3504 KB answer = YES
39 Correct 23 ms 5624 KB answer = YES
40 Correct 2 ms 3416 KB answer = YES
41 Correct 1 ms 3420 KB answer = NO
42 Correct 40 ms 5656 KB answer = YES
43 Correct 44 ms 5468 KB answer = YES
44 Correct 42 ms 7516 KB answer = YES
45 Correct 1 ms 3416 KB answer = YES
46 Correct 21 ms 5464 KB answer = YES
47 Correct 2 ms 5464 KB answer = YES
48 Correct 1 ms 5464 KB answer = YES
49 Correct 433 ms 4188 KB answer = YES
50 Correct 6 ms 6588 KB answer = YES
51 Correct 404 ms 4704 KB answer = YES
52 Correct 3 ms 4700 KB answer = NO
53 Correct 41 ms 5468 KB answer = YES
54 Correct 95 ms 5736 KB answer = YES
55 Correct 204 ms 3932 KB answer = YES
56 Correct 415 ms 6212 KB answer = YES
57 Correct 430 ms 4184 KB answer = YES
58 Correct 358 ms 5980 KB answer = YES
59 Correct 5 ms 4184 KB answer = YES
60 Correct 424 ms 4188 KB answer = YES
61 Correct 3 ms 5720 KB answer = YES
62 Correct 30 ms 11404 KB answer = NO
63 Correct 41 ms 12020 KB answer = YES
64 Correct 31 ms 11856 KB answer = NO
65 Correct 42 ms 11912 KB answer = YES
66 Correct 80 ms 5720 KB answer = YES
67 Execution timed out 1022 ms 18892 KB Time limit exceeded
68 Halted 0 ms 0 KB -