Submission #243220

#TimeUsernameProblemLanguageResultExecution timeMemory
243220NightlightCheap flights (LMIO18_pigus_skrydziai)C++14
100 / 100
526 ms32180 KiB
#include <bits/stdc++.h> #define pii pair<int, int> #define piii tuple<int, int, int> using namespace std; int N, M; vector<pii> adj[300005]; int deg[300005]; long long res[300005]; piii edge[300005]; int vis[300005]; long long ada[300005]; long long ans; bool comp(int a, int b) { return deg[a] == deg[b] ? a > b : deg[a] > deg[b]; } int main() { scanf("%d %d", &N, &M); int u, v, w; for(int i = 1; i <= M; i++) { scanf("%d %d %d", &u, &v, &w); deg[u]++, deg[v]++; ada[u] += w, ada[v] += w; edge[i] = make_tuple(u, v, w); } for(int i = 1; i <= M; i++) { tie(u, v, w) = edge[i]; if(comp(u, v)) adj[u].emplace_back(v, w); else adj[v].emplace_back(u, w); } for(int u = 1; u <= N; u++) { ans = max(ans, ada[u]); for(pii v : adj[u]) { vis[v.first] = v.second; } for(pii v : adj[u]) { for(pii w : adj[v.first]) { if(vis[w.first]) { ans = max(ans, (long long) vis[v.first] + vis[w.first] + w.second); } } } for(pii v : adj[u]) { vis[v.first] = 0; } } printf("%lld\n", ans); cin >> N; }

Compilation message (stderr)

pigus_skrydziai.cpp: In function 'int main()':
pigus_skrydziai.cpp:20:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &N, &M);
   ~~~~~^~~~~~~~~~~~~~~~~
pigus_skrydziai.cpp:23:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d", &u, &v, &w);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...