Submission #342897

# Submission time Handle Problem Language Result Execution time Memory
342897 2021-01-03T07:52:13 Z urd05 Graph (BOI20_graph) C++14
0 / 100
3 ms 2688 KB
#include <bits/stdc++.h>
using namespace std;

typedef pair<int,int> P;
vector<P> adj[100000];
P arr[100000];
bool visited[100000];
int ret[100000];
int chosen=-1e9; //두 배를 저장
const int nn=-1e9;
vector<int> save;

void dfs(int v,int x,int y) {
    if (visited[v]) {
        if (chosen==nn) {
            if (arr[v].first==x) {
                if (arr[v].second!=y) {
                    printf("NO");
                    exit(0);
                }
            }
            else {
                chosen=(2*(arr[v].second-y))/(x-arr[v].first);
            }
        }
        else  {
            if (x*chosen+y*2!=arr[v].first*chosen+arr[v].second*2) {
                printf("NO");
                exit(0);
            }
        }
        return;
    }
    visited[v]=true;
    save.push_back(v);
    arr[v].first=x;
    arr[v].second=y;
    for(int i=0;i<adj[v].size();i++) {
        dfs(adj[v][i].first,-x,-y+adj[v][i].second);
    }
}

int main(void) {
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i=0;i<m;i++) {
        int u,v,c;
        scanf("%d %d %d",&u,&v,&c);
        u--;
        v--;
        adj[u].push_back(P(v,c));
        adj[v].push_back(P(u,c));
    }
    for(int v=0;v<n;v++) {
        if (!visited[v]) {
            arr[v]=P(1,0);
            dfs(v,1,0);
            if (chosen==nn) {
                vector<int> vec;
                for(int i=0;i<save.size();i++) {
                    int now=save[i];
                    if (arr[now].first==1) {
                        vec.push_back(-arr[now].second);
                    }
                    else if (arr[now].first==-1) {
                        vec.push_back(arr[now].second);
                    }
                }
                sort(vec.begin(),vec.end());
                chosen=vec[vec.size()/2]*2;
            }
            for(int i=0;i<save.size();i++) {
                int now=save[i];
                ret[now]=arr[now].first*chosen+arr[now].second*2;
            }
            save.clear();
        }
    }
    for(int i=0;i<n;i++) {
        if (ret[i]>=0)
            printf("%d.%d ",ret[i]/2,(ret[i]%2)*5);
        else
            printf("-%d.%d",(-ret[i])/2,((-ret[i])%2)*5);
    }
}

Compilation message

Graph.cpp: In function 'void dfs(int, int, int)':
Graph.cpp:38:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |     for(int i=0;i<adj[v].size();i++) {
      |                 ~^~~~~~~~~~~~~~
Graph.cpp: In function 'int main()':
Graph.cpp:60:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |                 for(int i=0;i<save.size();i++) {
      |                             ~^~~~~~~~~~~~
Graph.cpp:72:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |             for(int i=0;i<save.size();i++) {
      |                         ~^~~~~~~~~~~~
Graph.cpp:45:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   45 |     scanf("%d %d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~
Graph.cpp:48:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   48 |         scanf("%d %d %d",&u,&v,&c);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2688 KB Expected YES or NO
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2688 KB Expected YES or NO
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2688 KB Expected YES or NO
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2688 KB Expected YES or NO
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2688 KB Expected YES or NO
2 Halted 0 ms 0 KB -