답안 #1021179

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1021179 2024-07-12T15:15:16 Z Nika533 Designated Cities (JOI19_designated_cities) C++14
9 / 100
156 ms 35408 KB
#pragma gcc diagnostic "-std=c++1z"
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define f first
#define s second
#define MOD 1000000007
#define pii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
using namespace std;

const int N=2e5+5;
int n,m,T,k,q,tot,sum,val[N];
int ans=1e18;
pii mx={0,0};
vector<pair<int,pii>> g[N];

void dfs0(int x, int p) {
     for (auto A:g[x]) {
          int y=A.f,w1=A.s.f,w2=A.s.s;
          if (y==p) continue;
          sum+=w2; dfs0(y,x);
     }
}
void dfs1(int x, int p) {
     val[x]=sum;
     for (auto A:g[x]) {
          int y=A.f,w1=A.s.f,w2=A.s.s;
          if (y==p) continue;
          sum+=w1-w2; dfs1(y,x); sum-=w1-w2; 
     }
}
void dfs(int x, int p, int dist) {
     mx=max(mx,{dist+val[x],x});
     for (auto A:g[x]) {
          int y=A.f,w1=A.s.f,w2=A.s.s;
          if (y==p) continue;
          dfs(y,x,dist+w1+w2);
     }
}

void test_case() {
     cin>>n;
     for (int i=1; i<=n-1; i++) {
          int a,b,c,d; cin>>a>>b>>c>>d;
          g[a].pb({b,{c,d}}); g[b].pb({a,{d,c}});
          tot+=c+d;
     }
     cin>>q;
     int query[q+1];
     for (int i=1; i<=q; i++) cin>>query[i];

     dfs0(1,0); dfs1(1,1);

     dfs(1,0,val[1]); int r1=mx.s; dfs(r1,0,val[r1]); int r2=mx.s;

     cout<<tot-mx.f/2<<endl;
}
main () {
	ios :: sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	T=1; 
	while (T--) test_case();
}

Compilation message

designated_cities.cpp:1: warning: ignoring '#pragma gcc diagnostic' [-Wunknown-pragmas]
    1 | #pragma gcc diagnostic "-std=c++1z"
      | 
designated_cities.cpp: In function 'void dfs0(long long int, long long int)':
designated_cities.cpp:21:21: warning: unused variable 'w1' [-Wunused-variable]
   21 |           int y=A.f,w1=A.s.f,w2=A.s.s;
      |                     ^~
designated_cities.cpp: In function 'void test_case()':
designated_cities.cpp:56:59: warning: unused variable 'r2' [-Wunused-variable]
   56 |      dfs(1,0,val[1]); int r1=mx.s; dfs(r1,0,val[r1]); int r2=mx.s;
      |                                                           ^~
designated_cities.cpp: At global scope:
designated_cities.cpp:60:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   60 | main () {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 119 ms 26048 KB Output is correct
3 Correct 156 ms 35408 KB Output is correct
4 Correct 125 ms 24788 KB Output is correct
5 Correct 116 ms 25872 KB Output is correct
6 Correct 124 ms 27800 KB Output is correct
7 Correct 87 ms 24056 KB Output is correct
8 Correct 156 ms 32548 KB Output is correct
9 Correct 73 ms 23656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4956 KB Output isn't correct
2 Halted 0 ms 0 KB -