Submission #52650

#TimeUsernameProblemLanguageResultExecution timeMemory
52650SpaimaCarpatilorTeleporters (IOI08_teleporters)C++17
10 / 100
665 ms87084 KiB
#include<bits/stdc++.h> using namespace std; int N, M, nr, v[2000009], nxt[2000009], gain[2000009], ap[2000009]; const int K = 2000001; int main () { //freopen ("input", "r", stdin); //freopen ("output", "w", stdout); scanf ("%d %d", &N, &M); for (int i=1; i<K; i++) nxt[i] = i; nxt[K] = 1; for (int i=1; i<=N; i++) { int x, y; scanf ("%d %d", &x, &y); gain[x] = gain[y] = 1; swap (nxt[x], nxt[y]); } for (int i=1; i<=K; i++) if (ap[i] == 0) { int j = i, s = 0; while (ap[j] == 0) ap[j] = 1, s += gain[j], j = nxt[j]; v[++nr] = s; } sort (v + 2, v + nr + 1); while (M > 0 && nr > 1) v[1] += v[nr] + 2, nr --, M --; if (M > 0) v[1] += 2 * M - M % 2; printf ("%d\n", v[1]); return 0; }

Compilation message (stderr)

teleporters.cpp: In function 'int main()':
teleporters.cpp:13:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 scanf ("%d %d", &N, &M);
 ~~~~~~^~~~~~~~~~~~~~~~~
teleporters.cpp:20:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf ("%d %d", &x, &y);
     ~~~~~~^~~~~~~~~~~~~~~~~
#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...
#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...
#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...
#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...