답안 #1021134

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1021134 2024-07-12T14:42:54 Z Nika533 Designated Cities (JOI19_designated_cities) C++14
7 / 100
148 ms 32580 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,ans=1e18;
vector<pair<int,pii>> g[N];

void dfs0(int x, int p) {
     // cout<<"X "<<x<<" "<<p<<endl;
     for (auto A:g[x]) {
          int y=A.f,w1=A.s.f,w2=A.s.s;
          if (y==p) continue;
          tot-=w2; dfs0(y,x);
     }
}
void dfs(int x, int p) {
     ans=min(ans,tot);
     for (auto A:g[x]) {
          int y=A.f,w1=A.s.f,w2=A.s.s;
          if (y==p) continue;
          tot-=w1-w2; dfs(y,x); tot+=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); dfs(1,1);

     cout<<ans<<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:20:21: warning: unused variable 'w1' [-Wunused-variable]
   20 |           int y=A.f,w1=A.s.f,w2=A.s.s;
      |                     ^~
designated_cities.cpp: At global scope:
designated_cities.cpp:50:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   50 | main () {
      | ^~~~
# 결과 실행 시간 메모리 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 111 ms 24720 KB Output is correct
3 Correct 148 ms 32076 KB Output is correct
4 Correct 88 ms 23112 KB Output is correct
5 Correct 106 ms 24324 KB Output is correct
6 Correct 110 ms 25680 KB Output is correct
7 Correct 90 ms 23448 KB Output is correct
8 Correct 134 ms 32580 KB Output is correct
9 Correct 70 ms 22520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4952 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 111 ms 24720 KB Output is correct
3 Correct 148 ms 32076 KB Output is correct
4 Correct 88 ms 23112 KB Output is correct
5 Correct 106 ms 24324 KB Output is correct
6 Correct 110 ms 25680 KB Output is correct
7 Correct 90 ms 23448 KB Output is correct
8 Correct 134 ms 32580 KB Output is correct
9 Correct 70 ms 22520 KB Output is correct
10 Incorrect 2 ms 4952 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4956 KB Output isn't correct
2 Halted 0 ms 0 KB -