답안 #121973

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
121973 2019-06-27T10:14:43 Z KLPP Designated Cities (JOI19_designated_cities) C++14
7 / 100
516 ms 43384 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> inv[200000];
bool visited[200000];
lld size[200000];
lld size2[200000];
void DFS(int node){
  visited[node]=true;
  size[node]=0;
  trav(p,nei[node]){
    if(!visited[p.first]){
      DFS(p.first);
      size[node]+=size[p.first]+p.second;
      size2[p.first]=-p.second;
    }
  }
}

void DFS2(int node){
  visited[node]=true;
  trav(p,inv[node]){
    if(!visited[p.first]){
      //cout<<node<<" "<<p.first<<" "<<p.second<<endl;
      size2[p.first]+=size2[node]+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));
    inv[x].push_back(pii(y,w));
    inv[y].push_back(pii(x,z));
  }
  rep(i,0,n)visited[i]=false;
  DFS(0);
  size2[0]=size[0];
  rep(i,0,n)visited[i]=false;
  DFS2(0);
  lld ans=size2[0];
  rep(i,0,n){
    ans=min(ans,size2[i]);
    //cout<<size2[i]<<endl;
  }
  printf("%lld\n",ans);
  return 0;
}

Compilation message

designated_cities.cpp: In function 'int main()':
designated_cities.cpp:37:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&n);
   ~~~~~^~~~~~~~~
designated_cities.cpp:41: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 10 ms 9728 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 9728 KB Output is correct
2 Correct 453 ms 35192 KB Output is correct
3 Correct 514 ms 42636 KB Output is correct
4 Correct 506 ms 35576 KB Output is correct
5 Correct 458 ms 35308 KB Output is correct
6 Correct 462 ms 37096 KB Output is correct
7 Correct 369 ms 34228 KB Output is correct
8 Correct 516 ms 43384 KB Output is correct
9 Correct 271 ms 33856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 9728 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 9728 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 9728 KB Output is correct
2 Correct 453 ms 35192 KB Output is correct
3 Correct 514 ms 42636 KB Output is correct
4 Correct 506 ms 35576 KB Output is correct
5 Correct 458 ms 35308 KB Output is correct
6 Correct 462 ms 37096 KB Output is correct
7 Correct 369 ms 34228 KB Output is correct
8 Correct 516 ms 43384 KB Output is correct
9 Correct 271 ms 33856 KB Output is correct
10 Incorrect 9 ms 9728 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 9728 KB Output isn't correct
2 Halted 0 ms 0 KB -