Submission #1126655

#TimeUsernameProblemLanguageResultExecution timeMemory
1126655TVSownCities (BOI16_cities)C++20
0 / 100
538 ms26692 KiB
///*** Sown_Vipro ***/// /// ->NHI QUOC GIA<- /// #include<bits/stdc++.h> using namespace std; //#pragma GCC optimize ("O3") //#pragma GCC optimize ("unroll-loops") //#pragma GCC target("popcnt") #define F first #define S second #define pb push_back #define pi pair<int, int> #define pii pair<int, pair<int, int> > #define FOR(i, a, b) for(int i = a; i <= b; ++i) #define REP(i, a, b) for(int i = a; i >= b; --i) #define all(s) s.begin(), s.end() #define szz(s) int(s.size()) const string NAME = "sown"; const int N = 1e6 + 5, MAX = 1e6, oo = 1e9 + 5, MOD = 1e9 + 7; void maxi(int &x, int y){ if(x < y) x = y; } void mini(int &x, int y){ if(x > y) x = y; }; void add(int &x, int y){ x += y; x += MOD * (x < 0); x -= MOD * (x >= MOD); }; int n, k, m, res = oo; int trace[N], spe[N]; long long d[N], dp[(1 << 5) + 5]; struct edge{ int u, v, w; } e[N]; vector<int> adj[N]; vector<int> s[(1 << 5) + 5]; int vst[N]; void dfs(int u){ vst[u] = 1; for(int v : adj[u]){ if(!vst[v]) dfs(v); } } void solve(){ cin >> n >> k >> m; FOR(i, 1, k){ int u; cin >> u; spe[i] = u; dp[u] = 0; s[(1 << i - 1)].pb(u); } FOR(i, 1, m){ int u, v, w; cin >> u >> v >> w; e[i] = {u, v, w}; } FOR(mask, 0, (1 << m) - 1){ int sum = 0; FOR(i, 1, m){ if(mask & (1 << i - 1)){ adj[e[i].u].pb(e[i].v); adj[e[i].v].pb(e[i].u); sum += e[i].w; } } // cout << mask << " " << sum << "\n"; dfs(spe[1]); int check = 1; FOR(i, 1, k) if(!vst[spe[i]]) check = 0; if(check){ mini(res, sum); // if(sum == 21){ // FOR(i, 1, m){ // if(mask & (1 << i - 1)) cout << e[i].u << " " << e[i].v << " " << e[i].w << "\n"; // } // cout << sum << "\n"; // } } FOR(u, 1, n){ vst[u] = 0; adj[u].clear(); } } cout << res; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); if(fopen((NAME + ".inp").c_str(), "r")){ freopen((NAME + ".inp").c_str(), "r", stdin); // freopen((NAME + ".out").c_str(), "w", stdout); } int t = 1; // cin >> t; while(t--){ solve(); } }

Compilation message (stderr)

cities.cpp: In function 'int main()':
cities.cpp:88:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   88 |         freopen((NAME + ".inp").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...