195232025-12-12 16:27:06szabelrHírlánccpp17Forditási hiba
// hirlanc.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

int main()
{
    int n,x,tanulo=1;
    unordered_map <int, int> pairs;
    cin >> n;
    int best[200001];
    for (int i = 1; i <= n; i++)
    {
        cin >> x;
        pairs[i]=x;
        best[i] = 0;
    }
    
    int maxi = 0;
    
    for (int i = 1; i <= n; i++)
    {
        if (best[i] == 0) {
            int k = i;
            int og = i;
            vector<int> pontok;
            vector<int> hely(n+1,-1);
            while (hely[k]==-1 and best[k]==0)
            {
                pontok.push_back(k);
                hely[k] = pontok.size() - 1;
                k = pairs[k];
            }
            if (best[k] != 0)
            {
                int a = best[k] + 1;
                for (int y = pontok.size() - 1; y >= 0; y--)
                {
                    best[pontok[y]] = a;
                    a++;
                }
            }
            else
            {
                int size = pontok.size() - hely[k];
                for (int j = hely[k]; j <= pontok.size() - 1; j++)
                {
                    best[pontok[j]] = size;

                }
                int a = best[k] + 1;
                for (int j = hely[k] - 1; j >= 0; j--)
                {
                    best[pontok[j]] = a;
                    a++;

                }
            }
            
            if (best[i] > maxi)
            {
                maxi = best[i];
                tanulo = i;
            }
        }
    }
    cout << tanulo<<" "<<maxi;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
Forditási hiba
open /var/local/lib/isolate/439/box/a.out: no such file or directory
main.cpp: In function 'int main()':
main.cpp:30:13: error: 'vector' was not declared in this scope
   30 |             vector<int> pontok;
      |             ^~~~~~
main.cpp:8:1: note: 'std::vector' is defined in header '<vector>'; did you forget to '#include <vector>'?
    7 | #include <set>
  +++ |+#include <vector>
    8 | using namespace std;
main.cpp:30:20: error: expected primary-expression before 'int'
   30 |             vector<int> pontok;
      |                    ^~~
main.cpp:31:20: error: expected primary-expression before 'int'
   31 |             vector<int> hely(n+1,-1);
      |                    ^~~
main.cpp:32:20: error: 'hely' was not declared in this scope
   32 |             while (hely[k]==-1 and best[k]==0)
      |                    ^~~~
main.cpp:34:17: error: 'pontok' was not declared in this scope
   34 |                 pontok.push_back(k);
      |                 ^~~~~~
main.cpp:41:30: error: 'pontok' was not declared in this scope
   41 |                 for (int y = pontok.size() - 1; y >= 0; y--)
      |                              ^~~~~~
main.cpp:49:28: error: 'pontok' was not declared in this scope
   49 |                 int size = pontok.size() - hely[k];
      |                            ^~~~~~
main.cpp:49:44: error: 'hely' was not declared in this scope
   49 |                 int size = pontok.size() - hely[k];
      |                                            ^~~~