답안 #121948

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
121948 2019-06-27T09:08:14 Z KLPP Designated Cities (JOI19_designated_cities) C++14
7 / 100
514 ms 43996 KB
#include<bits/stdc++.h>

using namespace std;
typedef long long int lld;
typedef pair<lld,lld> pii;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define trav(a,v) for(auto a:v)
vector<pii> nei[200000];
vector<pii> nei_d[200000];
lld dist[200000];
bool visited[200000];
void DFS(int node){
  //cout<<node<<endl;
  visited[node]=true;
  trav(p,nei_d[node]){
    if(!visited[p.first]){
      dist[p.first]=dist[node]+p.second;
      DFS(p.first);
    }
  }
}
lld ans;
void DFS2(int node){
  visited[node]=true;
  trav(p,nei[node]){
    if(!visited[p.first]){
      ans+=p.second;
      DFS2(p.first);
    }
  }
}
int main(){
  int n;
  scanf("%d",&n);
  rep(i,0,n-1){
    int x,y;
    lld z,w;
    scanf("%d %d %lld %lld",&x,&y,&z,&w);
    x--;y--;
    nei[x].push_back(pii(y,z));
    nei[y].push_back(pii(x,w));
    nei_d[x].push_back(pii(y,z-w));
    nei_d[y].push_back(pii(x,w-z));
  }
  rep(i,0,n){
    dist[i]=0;
    visited[i]=false;
  }
  dist[0]=0;
  DFS(0);
  //rep(i,0,n)cout<<dist[i]<<endl;
  pii best=pii(0,0);
  rep(i,0,n){
    best=max(best,pii(dist[i],i));
  }
  int start=best.second;
  ans=0;
  rep(i,0,n)visited[i]=false;
  DFS2(start);
  printf("%lld\n",ans);
  return 0;
}

Compilation message

designated_cities.cpp: In function 'int main()':
designated_cities.cpp:34:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&n);
   ~~~~~^~~~~~~~~
designated_cities.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %lld %lld",&x,&y,&z,&w);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 9728 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 9728 KB Output is correct
2 Correct 444 ms 31864 KB Output is correct
3 Correct 500 ms 42992 KB Output is correct
4 Correct 437 ms 37096 KB Output is correct
5 Correct 428 ms 38456 KB Output is correct
6 Correct 467 ms 39624 KB Output is correct
7 Correct 356 ms 37200 KB Output is correct
8 Correct 514 ms 43996 KB Output is correct
9 Correct 270 ms 36920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 9728 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 9728 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 9728 KB Output is correct
2 Correct 444 ms 31864 KB Output is correct
3 Correct 500 ms 42992 KB Output is correct
4 Correct 437 ms 37096 KB Output is correct
5 Correct 428 ms 38456 KB Output is correct
6 Correct 467 ms 39624 KB Output is correct
7 Correct 356 ms 37200 KB Output is correct
8 Correct 514 ms 43996 KB Output is correct
9 Correct 270 ms 36920 KB Output is correct
10 Incorrect 10 ms 9728 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 9728 KB Output isn't correct
2 Halted 0 ms 0 KB -